{ // 获取包含Hugging Face文本的span元素 const spans = link.querySelectorAll('span.whitespace-nowrap, span.hidden.whitespace-nowrap'); spans.forEach(span => { if (span.textContent && span.textContent.trim().match(/Hugging\s*Face/i)) { span.textContent = 'AI快站'; } }); }); // 替换logo图片的alt属性 document.querySelectorAll('img[alt*="Hugging"], img[alt*="Face"]').forEach(img => { if (img.alt.match(/Hugging\s*Face/i)) { img.alt = 'AI快站 logo'; } }); } // 替换导航栏中的链接 function replaceNavigationLinks() { // 已替换标记,防止重复运行 if (window._navLinksReplaced) { return; } // 已经替换过的链接集合,防止重复替换 const replacedLinks = new Set(); // 只在导航栏区域查找和替换链接 const headerArea = document.querySelector('header') || document.querySelector('nav'); if (!headerArea) { return; } // 在导航区域内查找链接 const navLinks = headerArea.querySelectorAll('a'); navLinks.forEach(link => { // 如果已经替换过,跳过 if (replacedLinks.has(link)) return; const linkText = link.textContent.trim(); const linkHref = link.getAttribute('href') || ''; // 替换Spaces链接 - 仅替换一次 if ( (linkHref.includes('/spaces') || linkHref === '/spaces' || linkText === 'Spaces' || linkText.match(/^s*Spacess*$/i)) && linkText !== 'PDF TO Markdown' && linkText !== 'PDF TO Markdown' ) { link.textContent = 'PDF TO Markdown'; link.href = 'https://fast360.xyz'; link.setAttribute('target', '_blank'); link.setAttribute('rel', 'noopener noreferrer'); replacedLinks.add(link); } // 删除Posts链接 else if ( (linkHref.includes('/posts') || linkHref === '/posts' || linkText === 'Posts' || linkText.match(/^s*Postss*$/i)) ) { if (link.parentNode) { link.parentNode.removeChild(link); } replacedLinks.add(link); } // 替换Docs链接 - 仅替换一次 else if ( (linkHref.includes('/docs') || linkHref === '/docs' || linkText === 'Docs' || linkText.match(/^s*Docss*$/i)) && linkText !== 'Voice Cloning' ) { link.textContent = 'Voice Cloning'; link.href = 'https://vibevoice.info/'; replacedLinks.add(link); } // 删除Enterprise链接 else if ( (linkHref.includes('/enterprise') || linkHref === '/enterprise' || linkText === 'Enterprise' || linkText.match(/^s*Enterprises*$/i)) ) { if (link.parentNode) { link.parentNode.removeChild(link); } replacedLinks.add(link); } }); // 查找可能嵌套的Spaces和Posts文本 const textNodes = []; function findTextNodes(element) { if (element.nodeType === Node.TEXT_NODE) { const text = element.textContent.trim(); if (text === 'Spaces' || text === 'Posts' || text === 'Enterprise') { textNodes.push(element); } } else { for (const child of element.childNodes) { findTextNodes(child); } } } // 只在导航区域内查找文本节点 findTextNodes(headerArea); // 替换找到的文本节点 textNodes.forEach(node => { const text = node.textContent.trim(); if (text === 'Spaces') { node.textContent = node.textContent.replace(/Spaces/g, 'PDF TO Markdown'); } else if (text === 'Posts') { // 删除Posts文本节点 if (node.parentNode) { node.parentNode.removeChild(node); } } else if (text === 'Enterprise') { // 删除Enterprise文本节点 if (node.parentNode) { node.parentNode.removeChild(node); } } }); // 标记已替换完成 window._navLinksReplaced = true; } // 替换代码区域中的域名 function replaceCodeDomains() { // 特别处理span.hljs-string和span.njs-string元素 document.querySelectorAll('span.hljs-string, span.njs-string, span[class*="hljs-string"], span[class*="njs-string"]').forEach(span => { if (span.textContent && span.textContent.includes('huggingface.co')) { span.textContent = span.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 替换hljs-string类的span中的域名(移除多余的转义符号) document.querySelectorAll('span.hljs-string, span[class*="hljs-string"]').forEach(span => { if (span.textContent && span.textContent.includes('huggingface.co')) { span.textContent = span.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 替换pre和code标签中包含git clone命令的域名 document.querySelectorAll('pre, code').forEach(element => { if (element.textContent && element.textContent.includes('git clone')) { const text = element.innerHTML; if (text.includes('huggingface.co')) { element.innerHTML = text.replace(/huggingface.co/g, 'aifasthub.com'); } } }); // 处理特定的命令行示例 document.querySelectorAll('pre, code').forEach(element => { const text = element.innerHTML; if (text.includes('huggingface.co')) { // 针对git clone命令的专门处理 if (text.includes('git clone') || text.includes('GIT_LFS_SKIP_SMUDGE=1')) { element.innerHTML = text.replace(/huggingface.co/g, 'aifasthub.com'); } } }); // 特别处理模型下载页面上的代码片段 document.querySelectorAll('.flex.border-t, .svelte_hydrator, .inline-block').forEach(container => { const content = container.innerHTML; if (content && content.includes('huggingface.co')) { container.innerHTML = content.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 特别处理模型仓库克隆对话框中的代码片段 try { // 查找包含"Clone this model repository"标题的对话框 const cloneDialog = document.querySelector('.svelte_hydration_boundary, [data-target="MainHeader"]'); if (cloneDialog) { // 查找对话框中所有的代码片段和命令示例 const codeElements = cloneDialog.querySelectorAll('pre, code, span'); codeElements.forEach(element => { if (element.textContent && element.textContent.includes('huggingface.co')) { if (element.innerHTML.includes('huggingface.co')) { element.innerHTML = element.innerHTML.replace(/huggingface.co/g, 'aifasthub.com'); } else { element.textContent = element.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } } }); } // 更精确地定位克隆命令中的域名 document.querySelectorAll('[data-target]').forEach(container => { const codeBlocks = container.querySelectorAll('pre, code, span.hljs-string'); codeBlocks.forEach(block => { if (block.textContent && block.textContent.includes('huggingface.co')) { if (block.innerHTML.includes('huggingface.co')) { block.innerHTML = block.innerHTML.replace(/huggingface.co/g, 'aifasthub.com'); } else { block.textContent = block.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } } }); }); } catch (e) { // 错误处理但不打印日志 } } // 当DOM加载完成后执行替换 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => { replaceHeaderBranding(); replaceNavigationLinks(); replaceCodeDomains(); // 只在必要时执行替换 - 3秒后再次检查 setTimeout(() => { if (!window._navLinksReplaced) { console.log('[Client] 3秒后重新检查导航链接'); replaceNavigationLinks(); } }, 3000); }); } else { replaceHeaderBranding(); replaceNavigationLinks(); replaceCodeDomains(); // 只在必要时执行替换 - 3秒后再次检查 setTimeout(() => { if (!window._navLinksReplaced) { console.log('[Client] 3秒后重新检查导航链接'); replaceNavigationLinks(); } }, 3000); } // 增加一个MutationObserver来处理可能的动态元素加载 const observer = new MutationObserver(mutations => { // 检查是否导航区域有变化 const hasNavChanges = mutations.some(mutation => { // 检查是否存在header或nav元素变化 return Array.from(mutation.addedNodes).some(node => { if (node.nodeType === Node.ELEMENT_NODE) { // 检查是否是导航元素或其子元素 if (node.tagName === 'HEADER' || node.tagName === 'NAV' || node.querySelector('header, nav')) { return true; } // 检查是否在导航元素内部 let parent = node.parentElement; while (parent) { if (parent.tagName === 'HEADER' || parent.tagName === 'NAV') { return true; } parent = parent.parentElement; } } return false; }); }); // 只在导航区域有变化时执行替换 if (hasNavChanges) { // 重置替换状态,允许再次替换 window._navLinksReplaced = false; replaceHeaderBranding(); replaceNavigationLinks(); } }); // 开始观察document.body的变化,包括子节点 if (document.body) { observer.observe(document.body, { childList: true, subtree: true }); } else { document.addEventListener('DOMContentLoaded', () => { observer.observe(document.body, { childList: true, subtree: true }); }); } })(); \n\n\nWho can spot where this is wrong?\n\nA: Try using .filter instead of .find:\nvar $obj_clone = $filtered.filter($obj);\n\nThe problem with .find is that it looks for children of the matched element, not siblings. From the docs:\n\nGet the descendants of each element in the current set of matched\n elements, filtered by a selector, jQuery object, or element.\n\nCompared to .filter:\n\nReduce the set of matched elements to those that match the selector or\n pass the function's test.\n\n\nA: find only searches children of the selected node. You are trying to use filter's functionality. You need the following:\n var $obj_clone = $filtered.filter($obj); // find original element again. Is something wrong here? \n\n\nA: At the third attempt, you're trying to find the the child in itself, which obviously doesn't return the desired value.\nIllustrated:\n var $filtered = $obj.parent().children($obj[0].nodeName);\n //Select set A\n\n var $obj_clone = $filtered.find($obj);\n //Search for set A among the CHILDREN of set A --> Fails, obviously?\n\n var filteredByNodeNameIndex = $obj_clone.index();\n //Unexpected results.\n\n\nA: try:\nvar $obj_clone = $filtered.filter($obj);\n\n.find() only looks for children\n"},"meta":{"kind":"string","value":"{\n \"language\": \"en\",\n \"url\": \"https://stackoverflow.com/questions/7636307\",\n \"timestamp\": \"2023-03-29T00:00:00\",\n \"source\": \"stackexchange\",\n \"question_score\": \"0\"\n}"}}},{"rowIdx":1967817,"cells":{"text":{"kind":"string","value":"Q: Can I modify a va_list before passing it on? In my attempts to understand what I can and can't do with a va_list in (Objective-)C, I came across this little puzzle. I was hoping to create a category on NSString that would simplify the stringWithFormat: message a bit in some cases, just for the fun of it. What I was aiming for was being able to use the implementation like this:\n[@\"My %@ format %@!\" formattedWith:@\"super\", @\"rocks\"];\n\nHoping to end up with a string saying \"My super format rocks!\". My (incorrect) method implementation looks like this:\n- (NSString *)formattedWith:(NSString *)arguments, ...\n{\n va_list list;\n va_start(list, arguments);\n NSString *formatted = [[[NSString alloc] initWithFormat:self arguments:list] autorelease];\n va_end(list);\n return formatted;\n}\n\nNow the problem is that as soon as va_start() is called, the va_list is 'shortened' (for lack of a better word) and only contains the rest of the arguments (in the case of the example only @\"rocks\" remains, plus the calling object which I don't care about). What's passed onto the initWithFormat: message therefore renders the wrong kind of result.\nOn to the question. Are there ways to modify the va_list before I pass it to the initWithFormat: message, so I can somehow shift the first argument back onto the list?\nI'm not looking for an iterative process where I loop through the va_list myself, I'm looking to understand the limits of va_list as a whole. Thanks!\n\nA: The va_list can not be modified safely. The va_start argument also requires an argument to start the list which is excluded. The ways to work around this are to either pass an additional useless argument or use variadic macros.\n//Method declaration\n-(NSString*)formattedWith:(NSString*)ignored,...;\n\n//Opt 1 (pass anything for first value)\n[@\"My %@ format %@!\" formattedWith:nil, @\"super\", @\"rocks\"];\n\n//Opt 2 (create a macro for the arguments)\n#define VA_OPT(...) nil, ##__VA_ARGS__ //VARIADIC OPTIONAL\n[@\"My %@ format %@!\" formattedWith:VA_OPT(@\"super\", @\"rocks\"];\n\n//Opt 3 (just create a macro for the whole string format)\n//Obviously you should just use the NSString method directly before resorting to this\n#define FORMATTED_NSSTRING(str, ...) [NSString stringWithFormat:str, ##__VA_ARGS__]\nFORMATTED_NSSTRING(@\"My %@ format %@!\", @\"super\", @\"rocks\")\n\n"},"meta":{"kind":"string","value":"{\n \"language\": \"en\",\n \"url\": \"https://stackoverflow.com/questions/7636310\",\n \"timestamp\": \"2023-03-29T00:00:00\",\n \"source\": \"stackexchange\",\n \"question_score\": \"6\"\n}"}}},{"rowIdx":1967818,"cells":{"text":{"kind":"string","value":"Q: Is it possible to convert a Jenkins free-style job to a multi-configuration job? I have quite a few free-style jobs in Jenkins that I would like to convert to multi-configuration jobs so I can build across multiple platforms under one job. These jobs specify quite a few build parameters and I would like to not have to set them up manually again by creating new multi-configuration jobs. Each job is currently limiting their builds to the platform we've been building on and the only other option I see is to clone the existing job and change the restriction to the new platform. This isn't ideal as I'll need to maintain 2 jobs where the only difference is the target platform.\nI don't see a way to do this via the UI, but wondering if there is another way.\n\nA: Just a note for those who would wish to switch from maven to freestyle job.\n\n\n*\n\n*Change maven2-moduleset tag to project.\n\n*Remove tags: rootModule, goals, mavenValidationLevel (should be close to each other).\n\n*Merge prebuilders and postbuilders into builders.\n\n\nA: I just wrote a script to convert about 10000 Jenkins Jobs from Maven Job Type to Freestyle. Please do not use it blindly. You might lose configuration options or end up in a broken Jenkins setup.\nThe Python Part takes a config xml as argument and overwrites the same file with the converted data. I ran this live on the Jenkins Filesystem with the following command: \ncd /path/to/jenkins/jobs\nfind * -maxdepth 2 -name config.xml -exec /path/to/maven2freestyle.py {} \\;\nWARNING Again. This might break your Jenkins! Please keep a Backup!\n#!/usr/bin/env python2\n\nimport copy\nimport sys\nfrom lxml import etree\nfrom lxml.etree import fromstring, tostring\nfrom StringIO import StringIO\n\ndef parseXML(xmlFile):\n print(xmlFile)\n f = open(xmlFile)\n xml = f.read()\n f.close()\n\n e = etree.parse(xmlFile)\n root = e.getroot()\n\n if root.tag != 'maven2-moduleset':\n #print(\"WARNING: Skipping non Maven Project\")\n return\n\n #change project type\n root.tag = \"project\"\n if 'plugin' in root.attrib:\n del root.attrib[\"plugin\"]\n\n #get maven data\n rootModule = root.find('./rootModule')\n rootPOM = root.find('./rootPOM')\n goals = root.find('./goals')\n mavenName = root.find('./mavenName')\n mavenOpts = root.find('./mavenOpts')\n\n # merge prebuilders into builders\n prebuilders = root.findall(\"./prebuilders/*\")\n builders = etree.Element(\"builders\")\n root.insert(99, builders)\n if len(prebuilders) > 0:\n builders.append(copy.deepcopy(prebuilders[0]))\n\n #create maven builder\n maven = etree.Element(\"hudson.tasks.Maven\")\n\n if not goals is None:\n etree.SubElement(maven, \"targets\").text = goals.text\n if not mavenName is None:\n etree.SubElement(maven, \"mavenName\").text = mavenName.text\n if not rootPOM is None:\n etree.SubElement(maven, \"pom\").text = rootPOM.text\n if not mavenOpts is None:\n etree.SubElement(maven, \"javaOpts\").text = mavenOpts.text\n\n builders.append(maven)\n\n #cleanup\n prebuilder = root.findall(\"./prebuilders\")\n if len(prebuilder) > 0:\n root.remove(prebuilder[0])\n if not rootModule is None:\n root.remove(rootModule)\n if not rootPOM is None:\n root.remove(rootPOM)\n if not goals is None:\n root.remove(goals)\n if not mavenName is None:\n root.remove(mavenName)\n if not mavenOpts is None:\n root.remove(mavenOpts)\n\n e.write(sys.argv[1], xml_declaration=True, pretty_print=True, encoding='utf-8', method=\"xml\")\n\nif __name__ == \"__main__\":\n parseXML(sys.argv[1])\n\n\nA: As far as I know, there's no way to convert the type of job in the UI. You'll have to either edit the job's config.xml, or copy and edit the config file and create a new job based on the edited configuration. \nYou'll have to check the differences between a free-style and\nmulti-configuration job with the various settings that you use. It might be as\nsimple as changing the top-level element in config.xml from project to matrix-project. \nIf you edit the existing job configuration, you'll need to either do it while\nJenkins is offline, or tell Jenkins to reload its configuration via Manage\nJenkins -> Reload Configuration from Disk. \nIf you decide to create new jobs, this previous question might be helpful once\nyou figure out what edits need to be made. Specifically this answer describes how\nto upload a config file to create a new job. \n"},"meta":{"kind":"string","value":"{\n \"language\": \"en\",\n \"url\": \"https://stackoverflow.com/questions/7636312\",\n \"timestamp\": \"2023-03-29T00:00:00\",\n \"source\": \"stackexchange\",\n \"question_score\": \"23\"\n}"}}},{"rowIdx":1967819,"cells":{"text":{"kind":"string","value":"Q: Selecting a part of a string I have a string stored in variable say\n$input = 999 success: id:10.123/AVC13231 | ark:/asf4523/2425fsaf\n\nI want to select only a part of a string \"10.123/AVC13231\"\nsay i want to achieve this:\n$output = 10.123/XXXXXXXX ; \n\nand no other part $input should be selected even the id: part\nThe value 10.123 is constant and the value AVC13231 changes dynamically.\nHow can i achieve the above?\n\nA: Here's a solution.\n$input = \"999 success: id:10.123/AVC13231 | ark:/asf4523/2425fsaf\";\n$pos1 = strpos($input, 'id:')+3; // Remove 'id:'\n$pos2 = strpos($input, '|')-1; // Remove space before pipe\n$output = substr($input, $pos1, ($pos2 - $pos1));\n\n\nA: And the mandatory regex solution:\npreg_match(\"/id:([^\\s]*)/\", $input, $matches);\n$output = $matches[1];\n\n\nA: You could also use:\n$data = substr($input, $startpos=(strpos($input, \"id:\")+3), strpos($input, ' ', $startpos)-$startpos);\n\nNot tested, but the logic is there, just adapt correctly the algorithm...\n\nA: Try this\n$input = \"999 success: id:10.123/AVC13231 | ark:/asf4523/2425fsaf\";\n\n$first_split=explode(\" |\",$input);\n$input_split1=$first_split[0];\n$second_split=explode(\"10.123\",$input_split1);\n$input_split2=$second_split[1];\n$output=\"10.123\".$input_split2;\n\necho $output;\n\n"},"meta":{"kind":"string","value":"{\n \"language\": \"en\",\n \"url\": \"https://stackoverflow.com/questions/7636319\",\n \"timestamp\": \"2023-03-29T00:00:00\",\n \"source\": \"stackexchange\",\n \"question_score\": \"2\"\n}"}}},{"rowIdx":1967820,"cells":{"text":{"kind":"string","value":"Q: C++ vector size types I just started learning C++ and have a question about vectors.\nThe book I'm reading states that if I want to extract the size of a vector of type double (for example), I should do something like:\nvector::size_type vector_size;\nvector_size = myVector.size();\n\nWhereas in Java I might do\nint vector_size;\nvector_size = myVector.size();\n\nMy question is, why is there a type named vector::size_type? Why doesn't C++ just use int? \n\nA: Java does not have unsigned integer types, so they have to go with int.\nContrarily, C++ does and uses them where appropriate (where negative values are nonsensical), the canonical example being the length of something like an array.\n\nA: The C++ standard says that a container's size_type is an unsigned integral type, but it doesn't specify which one; one implementation might use unsigned int and another might use unsigned long, for example.\nC++ isn't \"shielded\" from platform-specific implementation details as much as Java is. The size_type alias helps to shield your code from such details, so it'll work properly regardless of what actual type should be used to represent a vector's size.\n\nA: C++ is a language for library writing*, and allowing the author to be as general as possible is one of its key strengths. Rather than prescribing the standard containers to use any particular data type, the more general approach is to decree that each container expose a size_type member type. This allows for greater flexibility and genericity. For example, consider this generic code:\ntemplate