{ // 获取包含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 !== '免费Z-image图片生成' && linkText !== '免费Z-image图片生成' ) { link.textContent = '免费Z-image图片生成'; link.href = 'https://zimage.run'; 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 !== 'Vibevoice' ) { link.textContent = 'Vibevoice'; link.href = 'https://vibevoice.info/'; replacedLinks.add(link); } // 替换Pricing链接 - 仅替换一次 else if ( (linkHref.includes('/pricing') || linkHref === '/pricing' || linkText === 'Pricing' || linkText.match(/^s*Pricings*$/i)) && linkText !== '免费去水印' ) { link.textContent = '免费去水印'; link.href = 'https://sora2watermarkremover.net/'; replacedLinks.add(link); } // 替换Enterprise链接 else if ( (linkHref.includes('/enterprise') || linkHref === '/enterprise' || linkText === 'Enterprise' || linkText.match(/^s*Enterprises*$/i)) && linkText !== 'LTX-2' ) { link.textContent = 'LTX-2'; link.href = 'https://ltx-2.run/'; 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, '免费Z-image图片生成'); } 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\n```\n\nhelp me out from this how get response from node.js server. just i want see the alert box of success message in html page"},"date":{"kind":"string","value":"2015/10/26"},"metadata":{"kind":"list like","value":["https://Stackoverflow.com/questions/33342344","https://Stackoverflow.com","https://Stackoverflow.com/users/5260379/"],"string":"[\n \"https://Stackoverflow.com/questions/33342344\",\n \"https://Stackoverflow.com\",\n \"https://Stackoverflow.com/users/5260379/\"\n]"},"response_j":{"kind":"string","value":"Your main slowdown here is that Console.Read() and Console.ReadLine() both \"echo\" your text on the screen - and the process of writing the text slows you WAY down. What you want to use, then, is Console.Readkey(true), which does not echo the pasted text. Here's an example that writes 100,000 characters in about 1 second. It may need some modification for your purposes, but I hope it's enough to give you the picture. Cheers!\n\n```\npublic void begin()\n\n { List lines = new List();\n string line = \"\";\n Console.WriteLine(\"paste text to begin\");\n int charCount = 0;\n DateTime beg = DateTime.Now;\n do\n {\n Chars = Console.ReadKey(true);\n if (Chars.Key == ConsoleKey.Enter)\n {\n lines.Add(line);\n line = \"\";\n }\n else\n {\n line += Chars.KeyChar;\n charCount++;\n }\n\n } while (charCount < 100000);\n Console.WriteLine(\"100,000 characters (\"+lines.Count.ToString(\"N0\")+\" lines) in \" + DateTime.Now.Subtract(beg).TotalMilliseconds.ToString(\"N0\")+\" milliseconds\");\n\n }\n\n```\n\nI'm pasting a 5 MB file with long lines of text on a machine with all cores active doing other things (99% CPU load) and getting 100,000 characters in 1,600 lines in 1.87 seconds."},"response_k":{"kind":"string","value":"I don't see that you need to preserve order? If so, use Parallel in combination with partitioner class since you're executing small tasks:\n\nSee [When to use Partitioner class?](https://stackoverflow.com/questions/4031820/when-to-use-partitioner-class) for example\n\nThis means you have to change datatype to `ConcurrentBag` or `ConcurrentDictionary`"}}},{"rowIdx":45,"cells":{"qid":{"kind":"number","value":72317,"string":"72,317"},"question":{"kind":"string","value":"I mountain bike about 4 times a week. I like to do jumps, but I wear a water backpack (water bladder, camelbak, whatever you'd like to call it). I wear it because I find that a water bottle doesn't hold enough water for me to do a long ride without having to stop to refill. My backpack holds about 100 oz of water, plus a multi tool, sunscreen, bug spray, my phone and keys, and maybe a snack or two. This means that it is heavy. I would guess that when full it is about 20 pounds. My friends tell me to take it off when doing jumps, but I find that it feels a bit awkward to take it off because I lose a significant amount of weight from doing so.\n\nI haven't noticed any sort of difference in how easy it is to clear a given jump when my backpack is on/off, but the technique I use definitely is different when I am wearing a backpack because it adds 20 pounds hanging off my back.\n\nDoes NOT wearing a backpack actually make jumping easier, or does it just make it more comfortable? Does anyone know of a different solution to carry both a good amount of water and tools without needing a backpack?\n\nEDIT: I forgot to say that my backpack has two straps, one that buckles at chest level and one that buckles at waist level, although no matter how tight I make it the bag still flops around due to all the tools and just stuff in general that I store in it."},"date":{"kind":"string","value":"2020/09/25"},"metadata":{"kind":"list like","value":["https://bicycles.stackexchange.com/questions/72317","https://bicycles.stackexchange.com","https://bicycles.stackexchange.com/users/53029/"],"string":"[\n \"https://bicycles.stackexchange.com/questions/72317\",\n \"https://bicycles.stackexchange.com\",\n \"https://bicycles.stackexchange.com/users/53029/\"\n]"},"response_j":{"kind":"string","value":"You have more control over weight on you than on the bike, so long as the pack is fitted nicely and doesn't bounce around too much. This doesn't just apply to jumps but all the time, as your bodyweight is part of your control but weight on the bike is passive. Imagine rolling over a tree root on a hardtail or even rigid forks. Weight attached to the bike must lift over the bump, but if you're off the saddle and riding properly your body and backpack float over the obstacle, barely rising.\n\nMoving a few kg/10-20lbs between frame and body is noticeable. I'm a perpetual mountain bike novice but ride a lot on road. On the MTB (hardtail) I either use a hydration pack similar to you, or copy my road kit: a litre bottle of water, tool bottle in a 2nd cage, and saddlebag on the bike. Even at my level (no big jumps, but the effect holds even for bunny-hops) bike handling is easier with the weight on my back, though it's fatiguing on a very long ride. This makes sense. When your weight is on your feet and hands rather than your saddle (i.e. most of the time when riding technically) your bodyweight is sprung on your legs - so is the backpack. When you jump, you launch your body into the air and the bike follows you. You launch a backpack with you, but extra weight on the bike has to follow you.\n\nNote that flopping around can be reduced with good packing (but not eliminated if you're jumping when the whole backpack will shift vertically. ). Extra layers of clothing can be used to wedge loose tools into place. You can also borrow an idea from big trekking backpacks - straps to compress the contents. These don't have to be integrated, and could be webbing, paracord, or bungee cord, pulled tight around the packed bag and tied (or more conveniently buckled). Some elastic in the chest strap helps too."},"response_k":{"kind":"string","value":"You tagged “dirt jumping” in the question. At a jump park, I would definitely remove the backpack. At the very least, you won’t risk blowing up the water bag or breaking a tool in the (inevitable) event of a crash.\n\nFor normal trail riding, it goes either way. Some people prefer the backpack, others prefer the on-bike solution. It’s really all up to you. It’s best to pick one solution and stick to it though; as you described, the difference in weight balance really does mess with your skills and technique.\n\nIf you want to carry stuff on the bike, it is common to use normal bottles and cages for water. Tools and supplies would normally be held with elastic or Velcro straps. Contrary to what Chris suggested, I would not recommend the use of a saddle bag: they flop around all over the place and sound like your bike is falling apart. They also make it harder to use a dropper post.\n\nA fanny pack is a common solution where I live: water goes in a bottle and cage, bike tools go in Velcro straps, and soft goods (keys, phone, snacks...) go in the fanny pack. You can pick a variety of sizes of fanny packs to suit your needs."}}},{"rowIdx":46,"cells":{"qid":{"kind":"number","value":4652084,"string":"4,652,084"},"question":{"kind":"string","value":"How to get the previous URL in Rails? Not the URL that you got a request from, but the one before that?\n\nBecause I'm getting an AJAX request, and I need the URL for the page they are currently on (or the URL before the AJAX)."},"date":{"kind":"string","value":"2011/01/10"},"metadata":{"kind":"list like","value":["https://Stackoverflow.com/questions/4652084","https://Stackoverflow.com","https://Stackoverflow.com/users/356849/"],"string":"[\n \"https://Stackoverflow.com/questions/4652084\",\n \"https://Stackoverflow.com\",\n \"https://Stackoverflow.com/users/356849/\"\n]"},"response_j":{"kind":"string","value":"Use \n\n```\n<%= url_for(:back) %>\n# if request.env[\"HTTP_REFERER\"] is set to \"http://www.example.com\"\n# => http://www.example.com\n\n```\n\n[here is more details.](http://api.rubyonrails.org/v3.2.14/classes/ActionView/Helpers/UrlHelper.html#method-i-url_for)"},"response_k":{"kind":"string","value":"In a web application there is no such thing as a previous url. The http protocol is stateless, so each request is independent of each other.\n\nYou could have the Javascript code, that sends a request back, send the current url with the request."}}},{"rowIdx":47,"cells":{"qid":{"kind":"number","value":36176700,"string":"36,176,700"},"question":{"kind":"string","value":"I am getting three different roles from server like this-\n\n```\n[\"ROLE_USER\", \"ROLE_MODERATOR\", \"ROLE_ADMIN\"]\n\n```\n\nor\n\n```\n[\"ROLE_USER\",\"ROLE_ADMIN\"]\n\n```\n\nIf the user is not a moderator i don't want to access some pages to that user in my angular js application.What should i do.?"},"date":{"kind":"string","value":"2016/03/23"},"metadata":{"kind":"list like","value":["https://Stackoverflow.com/questions/36176700","https://Stackoverflow.com","https://Stackoverflow.com/users/5384141/"],"string":"[\n \"https://Stackoverflow.com/questions/36176700\",\n \"https://Stackoverflow.com\",\n \"https://Stackoverflow.com/users/5384141/\"\n]"},"response_j":{"kind":"string","value":"[angular-permission](https://github.com/Narzerus/angular-permission) is a third party module, Check this [angular-permission](https://github.com/Narzerus/angular-permission) it may help you"},"response_k":{"kind":"string","value":"The Simple solution is check the user role and hide/show the pages based on the user role..\nDid all those things during login redirect."}}},{"rowIdx":48,"cells":{"qid":{"kind":"number","value":58931099,"string":"58,931,099"},"question":{"kind":"string","value":"Does anyone know how to convert a Hex color to HSL in PHP? I've searched but the functions that I’ve found don’t convert precisely the color."},"date":{"kind":"string","value":"2019/11/19"},"metadata":{"kind":"list like","value":["https://Stackoverflow.com/questions/58931099","https://Stackoverflow.com","https://Stackoverflow.com/users/7722662/"],"string":"[\n \"https://Stackoverflow.com/questions/58931099\",\n \"https://Stackoverflow.com\",\n \"https://Stackoverflow.com/users/7722662/\"\n]"},"response_j":{"kind":"string","value":"I think the mistake in the second answer is using integer division rather than fmod() when calculating the hue when red is the maximum colour value `$hue = (($green - $blue) / $delta) % 6;`\n\nI think the mistake in the first answer is in the saturation calculation -\nfor me `$s = $l > 0.5 ? $diff / (2 - $max - $min) : $diff / ($max + $min);` is a bit confusing to unpick\n\nSince usually when I want to convert RGB to HSL I want to adjust the lightness value to make a lighter or darker version of the same colour, I have built that into the function below by adding an optional $ladj percent value.\n\nThe $hex parameter can be either a hex string (with or without the '#') or an array of RGB values (between 0 and 255)\n\nThe return value is an HSL string ready to drop straight in to a CSS colour. ie the values are from 0 to 359 for hue and 0 to 100% for saturation and lightness.\n\nI think this works correctly (based on )\n\n```\nfunction hex2hsl($RGB, $ladj = 0) {\n//have we got an RGB array or a string of hex RGB values (assume it is valid!)\n if (!is_array($RGB)) {\n $hexstr = ltrim($RGB, '#');\n if (strlen($hexstr) == 3) {\n $hexstr = $hexstr[0] . $hexstr[0] . $hexstr[1] . $hexstr[1] . $hexstr[2] . $hexstr[2];\n }\n $R = hexdec($hexstr[0] . $hexstr[1]);\n $G = hexdec($hexstr[2] . $hexstr[3]);\n $B = hexdec($hexstr[4] . $hexstr[5]);\n $RGB = array($R,$G,$B);\n }\n// scale the RGB values to 0 to 1 (percentages)\n $r = $RGB[0]/255;\n $g = $RGB[1]/255;\n $b = $RGB[2]/255;\n $max = max( $r, $g, $b );\n $min = min( $r, $g, $b );\n// lightness calculation. 0 to 1 value, scale to 0 to 100% at end\n $l = ( $max + $min ) / 2;\n\n// saturation calculation. Also 0 to 1, scale to percent at end.\n $d = $max - $min;\n if( $d == 0 ){\n// achromatic (grey) so hue and saturation both zero\n $h = $s = 0; \n } else {\n $s = $d / ( 1 - abs( (2 * $l) - 1 ) );\n// hue (if not grey) This is being calculated directly in degrees (0 to 360)\n switch( $max ){\n case $r:\n $h = 60 * fmod( ( ( $g - $b ) / $d ), 6 );\n if ($b > $g) { //will have given a negative value for $h\n $h += 360;\n }\n break;\n case $g:\n $h = 60 * ( ( $b - $r ) / $d + 2 );\n break;\n case $b:\n $h = 60 * ( ( $r - $g ) / $d + 4 );\n break;\n } //end switch\n } //end else \n// make any lightness adjustment required\n if ($ladj > 0) {\n $l += (1 - $l) * $ladj/100;\n } elseif ($ladj < 0) {\n $l += $l * $ladj/100;\n }\n//put the values in an array and scale the saturation and lightness to be percentages\n $hsl = array( round( $h), round( $s*100), round( $l*100) );\n//we could return that, but lets build a CSS compatible string and return that instead\n $hslstr = 'hsl('.$hsl[0].','.$hsl[1].'%,'.$hsl[2].'%)';\n return $hslstr;\n}\n\n```\n\nIn real life I would break out the hex string to RGB array conversion and the percentage adjustment into separate functions, but have included them here for completeness.\n\nYou could also use the percent adjustment to shift the hue or saturation once you've got the colour in HSL format."},"response_k":{"kind":"string","value":"```\nfunction hexToHsl($hex) {\n $hex = array($hex[0].$hex[1], $hex[2].$hex[3], $hex[4].$hex[5]);\n $rgb = array_map(function($part) {\n return hexdec($part) / 255;\n }, $hex);\n\n $max = max($rgb);\n $min = min($rgb);\n\n $l = ($max + $min) / 2;\n\n if ($max == $min) {\n $h = $s = 0;\n } else {\n $diff = $max - $min;\n $s = $l > 0.5 ? $diff / (2 - $max - $min) : $diff / ($max + $min);\n\n switch($max) {\n case $rgb[0]:\n $h = ($rgb[1] - $rgb[2]) / $diff + ($rgb[1] < $rgb[2] ? 6 : 0);\n break;\n case $rgb[1]:\n $h = ($rgb[2] - $rgb[0]) / $diff + 2;\n break;\n case $rgb[2]:\n $h = ($rgb[0] - $rgb[1]) / $diff + 4;\n break;\n }\n\n $h /= 6;\n }\n\n return array($h, $s, $l);\n}\n\n```"}}},{"rowIdx":49,"cells":{"qid":{"kind":"number","value":38914843,"string":"38,914,843"},"question":{"kind":"string","value":"If possible, I'd like to reload a jQuery `prototype`/`function` after a delay without refresh all the page. \n\n```\nmy.prototype.reloadMe = function () {\n setTimeout(function(){\n my.reloadMe();\n },1000);\n alert('ok');\n};\n\n```\n\nI tried with a `setTimeout` in the function but it didn't work: it refreshs only one time.\n\nThanks for your suggestions or explanations."},"date":{"kind":"string","value":"2016/08/12"},"metadata":{"kind":"list like","value":["https://Stackoverflow.com/questions/38914843","https://Stackoverflow.com","https://Stackoverflow.com/users/6607318/"],"string":"[\n \"https://Stackoverflow.com/questions/38914843\",\n \"https://Stackoverflow.com\",\n \"https://Stackoverflow.com/users/6607318/\"\n]"},"response_j":{"kind":"string","value":"In your code you define a **prototype** function, and then you try to call it as an object function. You should get an error like \"`my.reloadMe()` is not a function\".\n\n```\nmy.prototype.reloadMe = function () {\n setTimeout(function(){\n my.reloadMe(); // \"my\" object does not contain \"reloadMe\" function \n },1000);\n alert('ok');\n};\n\n```\n\nIf you want to access this function, you can either call this prototype function explicitly:\n\n```\nsetTimeout(function(){\n my.prototype.reloadMe();\n}, 1000);\n\n```\n\nor instantiate your object and call this function:\n\n```\nsetTimeout(function(){\n new my().reloadMe();\n}, 1000);\n\n```\n\nwhich both do not sound correct.\n\nIt looks like the best solution is to name your anonymous function:\n\n```\nmy.prototype.reloadMe = function reload() {\n setTimeout(reload, 1000);\n alert('ok');\n};);\n\n```\n\n**Note 1:** in your code you use `setTimeOut`, while it is `setTimeout`. JS is case-sensitive. Perhaps, it can be a source of the error.\n\n**Note 2:** any of this code will make it run in an infinite loop. So, actually, you will get an alert every second. I hope that it is exactly what you are trying to achieve :)"},"response_k":{"kind":"string","value":"```js\n//Create your object:\r\n\nfunction myobject(){\r\n\n}\r\n\n//add prototype to that object\r\n\nmyobject.prototype.reloadMe = function(){\r\n\n // instead of recursion you can use interval\r\n\n setInterval(function () {\r\n alert('ok');\r\n }, 1000);\r\n}\r\n\n// instantiate that object\r\n\nvar my = new myobject();\r\n\n//call your function\r\n\nmy.reloadMe();\n```"}}},{"rowIdx":50,"cells":{"qid":{"kind":"number","value":49076,"string":"49,076"},"question":{"kind":"string","value":"I am trying to derive the pdf of the sum of independent random variables. At first i would like to do this for a simple case: sum of gaussian random variables. I was surprised to see that i don't get a gaussian density function when i sum an even number of gaussian random variables. I actually get:\n[![enter image description here](https://i.stack.imgur.com/AZuU1.png)](https://i.stack.imgur.com/AZuU1.png)\n\nwhich looks like two halfs of a gaussian distribution. On the other hand, when i sum an odd number of gaussian distributions i get the right distribution:\n\n[![enter image description here](https://i.stack.imgur.com/RD9B6.png)](https://i.stack.imgur.com/RD9B6.png)\n\nbelow the code i used to produce the results above:\n\n```\nimport numpy as np\nfrom scipy.stats import norm\nfrom scipy.fftpack import fft,ifft\nimport matplotlib.pyplot as plt\n%matplotlib inline\n\na=10**(-15)\nend=norm(0,1).ppf(a)\nsample=np.linspace(end,-end,1000)\npdf=norm(0,1).pdf(sample)\nplt.subplot(211)\nplt.plot(np.real(ifft(fft(pdf)**2)))\nplt.subplot(212)\nplt.plot(np.real(ifft(fft(pdf)**3)))\n\n```\n\nCould someone help me understand why i get odd results for even sums of gaussians distribution? Thanks in advance"},"date":{"kind":"string","value":"2018/05/08"},"metadata":{"kind":"list like","value":["https://dsp.stackexchange.com/questions/49076","https://dsp.stackexchange.com","https://dsp.stackexchange.com/users/35618/"],"string":"[\n \"https://dsp.stackexchange.com/questions/49076\",\n \"https://dsp.stackexchange.com\",\n \"https://dsp.stackexchange.com/users/35618/\"\n]"},"response_j":{"kind":"string","value":"The FFT algorithm expects the origin of the signal to be on the leftmost sample of the signal. You are convolving two shifted Gaussian together, yielding a Gaussian that is even more shifted. Because of the FFT imposes periodicity, when the curve is shifted past the right edge it comes back in on the left edge.\n\nWhit an odd number the shift is exactly the full width of the signal, so you don’t notice it. \n\nA solution would be to use a zero-mean Gaussian distribution, which you can obtain from yours by `ifftshift`. After performing the convolution, you can shift it back to where it was using `fftshift`.\n\n```\nnp.fft.fftshift(ifft(fft(np.fft.ifftshift(pdf))**2))\n\n```"},"response_k":{"kind":"string","value":"Perhaps you can use a kde function to estimate the kernel?\n\n```\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy import stats\n\nN = 10**4\nx12 = np.array([ [np.random.normal(),np.random.normal()] for i in range(N)])\nX = np.sort(x12[:,0] + x12[:,1])\ndensity = stats.kde.gaussian_kde(X)\nplt.plot(X,density(X))\n\n```\n\nIt might be slow, nevertheless, to run for large $N$."}}},{"rowIdx":51,"cells":{"qid":{"kind":"number","value":35667548,"string":"35,667,548"},"question":{"kind":"string","value":"**I am unable to call** \n\n```\n-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation\n\n```\n\n**On following IBAction**\n\n```\n- (IBAction)button:(UIButton *)sender {\n\n}\n\n```\n\nhelp me"},"date":{"kind":"string","value":"2016/02/27"},"metadata":{"kind":"list like","value":["https://Stackoverflow.com/questions/35667548","https://Stackoverflow.com","https://Stackoverflow.com/users/5718089/"],"string":"[\n \"https://Stackoverflow.com/questions/35667548\",\n \"https://Stackoverflow.com\",\n \"https://Stackoverflow.com/users/5718089/\"\n]"},"response_j":{"kind":"string","value":"Use sendgrid-java. It is pretty straight forward to send emails using this library.\n\n```\n SendGrid sendgrid = new SendGrid('YOUR_SENDGRID_API_KEY');\n\n SendGrid.Email email = new SendGrid.Email();\n email.addTo(\"example@example.com\");\n email.setFrom(\"other@example.com\");\n email.setSubject(\"Hello World\");\n email.setText(\"My first email with SendGrid Java!\");\n\n try {\n SendGrid.Response response = sendgrid.send(email);\n System.out.println(response.getMessage());\n }\n catch (SendGridException e) {\n System.err.println(e);\n }\n\n```"},"response_k":{"kind":"string","value":"As @Anil said, you can tried to send emails using the SendGrid SDK for Java, please see the library on GitHub , or directly add its [maven dependency](http://mvnrepository.com/artifact/com.sendgrid/sendgrid-java/) below into your maven project.\n\n```\n\n com.sendgrid\n sendgrid-java\n 2.2.2\n\n\n```\n\nThe other way is using the SendGrid REST API via HTTP using the Class `HTTPConnection` in Java, please see the docs for [WebAPI v2](https://sendgrid.com/docs/API_Reference/Web_API/index.html) or [WebAPI v3](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html)."}}},{"rowIdx":52,"cells":{"qid":{"kind":"number","value":141349,"string":"141,349"},"question":{"kind":"string","value":"What would be a cleaner way to write the following?\n\n```\n// Check if add user was attempted\nif ($params['submit']) {\n // Verify all fields are filled in\n if (Utilities::checkAllFieldsNotEmpty($params)) {\n // Make sure username is not taken\n if (Admin::checkUsername($params['username'])) {\n // Check if directory is created\n if (Admin::createUsersDirectory($params['username'])) {\n if (Admin::createNewUser($params['name'], $params['username'], $params['password'], $params['admin'])) {\n Utilities::setMessage(\"Excellent!\", \"User was created successfully.\", \"admin_modal\");\n }\n } else {\n Utilities::setMessage(\"Whoa!\", \"Directory creation failed.\", \"admin_modal\");\n }\n } else {\n Utilities::setMessage(\"Whoa!\", \"Username in use.\", \"admin_modal\");\n }\n } else {\n Utilities::setMessage(\"Whoa!\", \"Please fill in all fields\", \"admin_modal\");\n }\n\n // Return admin view with message\n return $this->view->render($response, 'admin/admin.twig', [\n 'name' => $user['name'],\n 'message' => $_SESSION['message'],\n 'form' => [\n 'name' => $params['name'],\n 'username' => $params['username'],\n 'admin' => $params['admin']\n ]\n ]);\n}\n\n```"},"date":{"kind":"string","value":"2016/09/14"},"metadata":{"kind":"list like","value":["https://codereview.stackexchange.com/questions/141349","https://codereview.stackexchange.com","https://codereview.stackexchange.com/users/74542/"],"string":"[\n \"https://codereview.stackexchange.com/questions/141349\",\n \"https://codereview.stackexchange.com\",\n \"https://codereview.stackexchange.com/users/74542/\"\n]"},"response_j":{"kind":"string","value":"Don't nest your conditions like this. Validate the input up front and fail out if need be.\n\nFor example that might look like this:\n\n```\nif(empty($params['submit'])) {\n // no parameters set\n // log error, throw exception, etc. as approrpiate\n}\nif(Utilities::checkAllFieldsNotEmpty($params) === false) {\n // fail out\n // not sure if you really need this condition if you validate each field\n // individually\n}\n// etc.\n\n```\n\nThen I would suggest that your Admin class should abstract away the details of user creation away from this script. Ideally this script could just have something like:\n\n```\ntry {\n $user = Admin::createNewUser(...);\n} catch (Exception $e) {\n // do something to handle exception\n}\n\n```\n\nAnd `createNewUser()` would go through all the logic of for validating user name, setting up directories, etc. This code should know nothing about what is required to create a \"user\" outside of whatever information needs to be passed (i.e. user name)."},"response_k":{"kind":"string","value":"Since at most one of the messages will be selected, you should invert the conditions to make it linear rather than nested. This has the benefit of putting each error message right next to its corresponding test.\n\n```\nif (!Utilities::checkAllFieldsNotEmpty($params)) {\n Utilities::setMessage(\"Whoa!\", \"Please fill in all fields\", \"admin_modal\");\n} elseif (!Admin::checkUsername($params['username'])) {\n Utilities::setMessage(\"Whoa!\", \"Username in use.\", \"admin_modal\");\n} elseif (!Admin::createUsersDirectory($params['username'])) {\n Utilities::setMessage(\"Whoa!\", \"Directory creation failed.\", \"admin_modal\");\n} elseif (Admin::createNewUser($params['name'], $params['username'], $params['password'], $params['admin'])) {\n Utilities::setMessage(\"Excellent!\", \"User was created successfully.\", \"admin_modal\");\n}\n\n```\n\nThere are still a couple of problems, though.\n\nFirst, I would say that the methods named `check…` do not clearly convey what they do. Based on those names, I would expect that they throw an exception if they fail the test. If they are actually predicates, it would be better to name them `Utilities::areAllFieldsNotEmpty(…)` and `Admin::isUsernameAvailable(…)`.\n\nA hint that something is wrong is that the `Admin::createNewUser(…)` call is not negated like the others. The problem is that you've forgotten to display an error message for that potential failure:\n\n```\n …\n} elseif (!Admin::createNewUser($params['name'], $params['username'], $params['password'], $params['admin'])) {\n Utilities::setMessage(\"Whoa!\", \"User creation failed!\", \"admin_modal\");\n} else {\n Utilities::setMessage(\"Excellent!\", \"User was created successfully.\", \"admin_modal\");\n}\n\n```"}}},{"rowIdx":53,"cells":{"qid":{"kind":"number","value":53242134,"string":"53,242,134"},"question":{"kind":"string","value":"In my project I have a Window called AccountWindow.xaml which has a ContentControl to display the two UserControls.\n\n**AccountWindow**\n\n```\n\n \n \n \n \n \n\n \n \n \n \n \n\n \n \n \n \n\n\n```\n\nI then have two user controls called LoginUserControl and RegistrationUserControl\n\n**Login User Control**\n\n```\n\n \n\n```\n\nor simply omit `this.form.submit();` (because that is what a submit button already does by itself when clicked):\n\n```\n\n\n```"},"response_k":{"kind":"string","value":"I would suggest you to disable the button by adding a disabled attribute to it once the user has submitted the form.\n\nYou can submit a form using javascript using `form.submit();`. This way you can remove type=\"submit\" and allows you to have more freedom in controlling the behaviour of onClick event.\n\nFor example:\n\n```js\nfunction myFunction() {\r\n document.getElementById(\"myBtn\").disabled = true;\r\n}\n```\n\n```html\n\n```"}}},{"rowIdx":61,"cells":{"qid":{"kind":"number","value":49225505,"string":"49,225,505"},"question":{"kind":"string","value":"I need to make text wrap around image with bootstrap 4 wihout floats, is it possible?\n\nHere my code:\n\n```\n
\n
\n \n
\n
\n \n
\n
\n\n```\n\nHere what I have now:\n[![enter image description here](https://i.stack.imgur.com/nwtsm.png)](https://i.stack.imgur.com/nwtsm.png)\n\nHere what I need to have:\n[![enter image description here](https://i.stack.imgur.com/ZnLBS.png)](https://i.stack.imgur.com/ZnLBS.png)"},"date":{"kind":"string","value":"2018/03/11"},"metadata":{"kind":"list like","value":["https://Stackoverflow.com/questions/49225505","https://Stackoverflow.com","https://Stackoverflow.com/users/4598861/"],"string":"[\n \"https://Stackoverflow.com/questions/49225505\",\n \"https://Stackoverflow.com\",\n \"https://Stackoverflow.com/users/4598861/\"\n]"},"response_j":{"kind":"string","value":"> \n> I need to make text wrap around image with bootstrap 4 wihout floats, is it possible?\n> \n> \n> \n\nNo, in this case, you must use the `float-left` class for the image. But you don't have to use any wrapper for the image. You can get rid of that wrapper div entirely and add your classes to the image. \n\nAnother thing you absolutely must do: \n\nPut all of your content into Bootstrap columns because only Bootstrap columns may be the direct children of Bootstrap rows. \n\nHere's a working code snippet (note: I left the image wrapper div in there but I recommend you get rid of it because that's totally unnecessary code. Add your classes directly to the image): \n\n```html\n\r\n\n
\r\n
\r\n
\r\n
\r\n \"\"\r\n
\r\n
\r\n Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nihil ad, ex eaque fuga minus reprehenderit asperiores earum incidunt. Possimus maiores dolores voluptatum enim soluta omnis debitis quam ab nemo necessitatibus.\r\n

\r\n Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nihil ad, ex eaque fuga minus reprehenderit asperiores earum incidunt. Possimus maiores dolores voluptatum enim soluta omnis debitis quam ab nemo necessitatibus.\r\n
\r\n
\r\n
\r\n
\n```"},"response_k":{"kind":"string","value":"```\n
\n
\n
\n
\n
\n

Title

\n

Some text here

\n
\n\n```\n\nI have used this in bootstrap 4."}}},{"rowIdx":62,"cells":{"qid":{"kind":"number","value":278886,"string":"278,886"},"question":{"kind":"string","value":"When I first learned about bowl feeders I thought that there was some sort of rotation that would cause it to go up, but apparently it is caused by vibrating the bowl.\n\nI do not understand how vibrations can cause a part to move upwards. From what I understand, vibrations will have a similar effect to reducing friction, which means that it would cause the parts to fall down the slope more easily.\n\nHow does it work? Is the vibration applied in a certain direction/rotation/etc. which causes this upward movement? Or is it just normal vibration?\n\nThere is [an article describing vibratory bowl feeders here](http://www.rnaautomation.com/products/feeding-and-handling/vibratory-feeders/), and [a YouTube video showing one in operation here](https://www.youtube.com/watch?v=QsJzSFVAnhk)."},"date":{"kind":"string","value":"2016/09/08"},"metadata":{"kind":"list like","value":["https://physics.stackexchange.com/questions/278886","https://physics.stackexchange.com","https://physics.stackexchange.com/users/81170/"],"string":"[\n \"https://physics.stackexchange.com/questions/278886\",\n \"https://physics.stackexchange.com\",\n \"https://physics.stackexchange.com/users/81170/\"\n]"},"response_j":{"kind":"string","value":"I found this answer at,\n\n\n\"Properly tuned, a feeder will vibrate properly but, by itself, vibration will do little more than make the parts bounce around. In order to make the parts move, the vibration must be focused in the desired direction. This is done by mounting the springs on an angle rather than vertically. As the feeder bowl rotates back and forth on its springs the angle causes it to move vertically as well. As it moves forward and up, friction pushes the part forward. As it moves back and down, the part falls vertically. This sawtooth motion can move parts gently at astonishing speeds.\""},"response_k":{"kind":"string","value":"The bowl feeder as well as its linear version based on the hysteresis of the involved spring-magnet device-system. Changing the frequency of the vibrations of the magnetic device you can make that the parts in the feeder will vibrate in standstill or will move backwards. A big difference in the load will do the same. Instead of electromagnets they use piezoelectric devices too, or for really big feeders simply an electro motor with a unbalanced weight on its axis."}}},{"rowIdx":63,"cells":{"qid":{"kind":"number","value":78392,"string":"78,392"},"question":{"kind":"string","value":"[Jacobian](http://en.wikipedia.org/wiki/Jacobian_matrix_and_determinant), [Lorentz](http://en.wikipedia.org/wiki/Lorentz_transformation) and [Fourier Transformation](http://en.wikipedia.org/wiki/Fourier_transform). I am confused with the physical interpretation/meaning of all these transformations. \n\n1. As far as I understood, Jacobian transforms from one coordinate space to another (there are examples for Jacobian from cartesian to spherical so and so...). But Lorentz transform also do similar transformation from one coordinate space to another right? So, Jacobian is also a kind of Lorentz transform! Or else what is the physical difference?\n2. Finally, I got confused with the Fourier transform as well! It also transform from one space to another!.\n\nHow can we explain the physical difference and physical usefulness of all these transforms? How we decide what transformation can be done in some physical situation? Can anyone please explain with physical example and comparing these three transformations?"},"date":{"kind":"string","value":"2013/09/24"},"metadata":{"kind":"list like","value":["https://physics.stackexchange.com/questions/78392","https://physics.stackexchange.com","https://physics.stackexchange.com/users/20190/"],"string":"[\n \"https://physics.stackexchange.com/questions/78392\",\n \"https://physics.stackexchange.com\",\n \"https://physics.stackexchange.com/users/20190/\"\n]"},"response_j":{"kind":"string","value":"It's sloppy language that is confusing you here.\n\n1. A Jacobian is not a transformation. The Jacobian *of a* transformation measures by how much the transformation expands or shrinks volume(/area/length/hypervolume/whatever) elements. Example: let $x' = 2x$. Then $dx = dx'/2$. The Jacobian is the $1/2$, meaning nothing more than \"a unit of the $x'$ scale has a length of 1/2 a unit on the $x$ scale.\" The formula involving partial derivatives and a determinant is the generalization of this to arbitrary dimensionality & coordinate transformations, but the meaning is exactly the same.\n2. Lorentz transformations are the transformations that preserve intervals in Minkowski spacetime. In terms of cartesian coordinate systems ($x,y,z,t$) they are the linear transformations that preserve $-\\mathrm{d}t^2 + \\mathrm{d}x^2 + \\mathrm{d}y^2 + \\mathrm{d}z^2$ and their Jacobian is $1$, i.e. they don't expand or shrink spacetime volume elements $\\mathrm{d}t\\mathrm{d}x\\mathrm{d}y\\mathrm{d}z$. In crazy weird coordinates Lorentz transformations would surely look awful, and you would have to do gymnastics to keep track of their Jacobian, but that just means that if you care about Lorentz invariance you shouldn't be using crazy weird coordinate systems. :)\n3. Fourier transforms are a change of basis on *function space*. You have a function on configuration space $f(x)$, say, and you would like to describe it by its wavenumber spectrum $\\tilde{f}(k)$ instead. Fourier transform gives you the connection between the two bases. The function hasn't changed, and the function space hasn't changed either, but you are using a different set of basis functions to \"map out\" the space. Functions which look local in configuration space, like $\\delta(x-x\\_0)$ map to extended waves in wavenumber space $\\exp(i x\\_0 k)$ and vice versa, so which basis is more convenient depends on the application. But try to keep clear that you are not mapping positions to wavenumbers or vice versa. You are mapping the *description of the abstract function $f$ in terms of local functions of coordinates $x$* into the *description of the same abstract function $f$ in terms of local functions of wavenumbers $k$*, no different from going from an abstract vector $\\vec{v}$ written in components in the $\\hat{x},\\hat{y},\\hat{z}$ basis to the same vector written in components in the $\\hat{x}',\\hat{y}',\\hat{z}'$ basis."},"response_k":{"kind":"string","value":"A **Fourier transform** is a linear transformation between two particular bases, the point functions and the periodic functions. The vector space we are talking about here is the space of functions.\n\nA **Jacobian matrix** is a linear approximation for a general transformation. For example, you mention transforming from a Cartesian basis to a spherical basis. This isn't a linear transformation, but we can approximate it as one if we restrict our attention to small regions of space.\n\nA Jacobian is the determinant of the Jacobian matrix.\n\nA **Lorentz transformation** is a linear transformation of space-time that has several additional restrictions (eg preserves the space-time interval, preserves parity) that are physical in nature."}}},{"rowIdx":64,"cells":{"qid":{"kind":"number","value":36947847,"string":"36,947,847"},"question":{"kind":"string","value":"I have always found the `range` function missing from JavaScript as it is available in python and others? Is there any concise way to generate range of numbers in ES2015 ?\n\nEDIT: MY question is different from the mentioned duplicate as it is specific to ES2015 and not ECMASCRIPT-5. Also I need the range to be starting from 0 and not specific starting number (though it would be good if that is there)"},"date":{"kind":"string","value":"2016/04/29"},"metadata":{"kind":"list like","value":["https://Stackoverflow.com/questions/36947847","https://Stackoverflow.com","https://Stackoverflow.com/users/3878940/"],"string":"[\n \"https://Stackoverflow.com/questions/36947847\",\n \"https://Stackoverflow.com\",\n \"https://Stackoverflow.com/users/3878940/\"\n]"},"response_j":{"kind":"string","value":"You can use the spread operator on the keys of a freshly created array.\n\n`[...Array(n).keys()]`\n\nor\n\n`Array.from(Array(n).keys())`\n\nThe `Array.from()` syntax is necessary if working with TypeScript"},"response_k":{"kind":"string","value":"A lot of these solutions build on instantiating real Array objects, which can get the job done for a lot of cases but can't support cases like `range(Infinity)`. You could use a simple generator to avoid these problems and support infinite sequences:\n\n```\nfunction* range( start, end, step = 1 ){\n if( end === undefined ) [end, start] = [start, 0];\n for( let n = start; n < end; n += step ) yield n;\n}\n\n```\n\nExamples:\n\n```\nArray.from(range(10)); // [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]\nArray.from(range(10, 20)); // [ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]\n\ni = range(10, Infinity);\ni.next(); // { value: 10, done: false }\ni.next(); // { value: 11, done: false }\ni.next(); // { value: 12, done: false }\ni.next(); // { value: 13, done: false }\ni.next(); // { value: 14, done: false }\n\n```"}}},{"rowIdx":65,"cells":{"qid":{"kind":"number","value":6059526,"string":"6,059,526"},"question":{"kind":"string","value":"Question:\n---------\n\nIs it posible to detect when a file, for wich a have an open FileStream, was renamed.\n\nCase:\n-----\n\nI am trying to monitor the logs for our application, I read from the logfiles since I do not want to interfere with the logging itself.\n\nThis works great until the file gets rolled. My application keeps reading from a renamed file without even noticing.\n\nI **tried** using a FileSystemWatcher to detect the roll, but sometimes a get a lot of events, sometimes I don't, so that's not really a good solution (also the logfiles could reside on a network share wich could be an extra hold-back for using a FSW).\n\nIf I could find out which file(name) I have an open handle to, I could compare that to the `_fileName` but I don't know how or if this can be done.\n\nAre there any other options I could explore?\n\nCode:\n-----\n\nthis is a simplified version of my filemonitoring class:\n\n```\npublic class MonitorFile\n{\n private String _fileName = String.Empty;\n private bool _stopMonitoring = false;\n\n public MonitorFile(string fileName)\n {\n _fileName = fileName;\n }\n\n // Simplified method\n public void StartMonitoring()\n {\n using (var reader = new StreamReader(\n new FileStream(\n _monitorFileName,\n FileMode.Open,\n FileAccess.Read,\n FileShare.Delete | FileShare.ReadWrite)))\n {\n while (!_stopMonitoring)\n {\n Thread.Sleep(500);\n\n while ((line = reader.ReadLine()) != null)\n {\n //...Do stuff with the lines\n }\n }\n }\n }\n}\n\n```"},"date":{"kind":"string","value":"2011/05/19"},"metadata":{"kind":"list like","value":["https://Stackoverflow.com/questions/6059526","https://Stackoverflow.com","https://Stackoverflow.com/users/366970/"],"string":"[\n \"https://Stackoverflow.com/questions/6059526\",\n \"https://Stackoverflow.com\",\n \"https://Stackoverflow.com/users/366970/\"\n]"},"response_j":{"kind":"string","value":"There is an MSDN example showing [how you can obtain a file name from a file handle](http://msdn.microsoft.com/en-us/library/aa366789%28v=vs.85%29.aspx) (which you have access to via the `Handle` property of the `FileStream`) using Win32 APIs, but I doubt this approach will work for files on a remote network share. \n\nYou may well be out of luck in the general case."},"response_k":{"kind":"string","value":"You could extract the directory name from the monitor file path.\nThen after your readLine loop:\nGet the file list in the directory, sorted by last updated date\ntake the first item in the list\ncompare it to the file name you are reading from and if they are different update your reader\n\nThis works on the assumption that only files in the directory will be log files and you are always wanting to be reading from the most recently updated file"}}},{"rowIdx":66,"cells":{"qid":{"kind":"number","value":44954872,"string":"44,954,872"},"question":{"kind":"string","value":"Does git allow (i.e., is there a valid use case) a `.git/` folder inside subfolders?\n\nOr is the `.git/` folder supposed to be only in one place and that is in the project's root location?"},"date":{"kind":"string","value":"2017/07/06"},"metadata":{"kind":"list like","value":["https://Stackoverflow.com/questions/44954872","https://Stackoverflow.com","https://Stackoverflow.com/users/2856202/"],"string":"[\n \"https://Stackoverflow.com/questions/44954872\",\n \"https://Stackoverflow.com\",\n \"https://Stackoverflow.com/users/2856202/\"\n]"},"response_j":{"kind":"string","value":"In general, the `.git` folder should only be at the project's root location (by design). However, the repository may be set up to use [git submodules](https://git-scm.com/docs/git-submodule), and this could result in subdirectories having their own `.git` folder."},"response_k":{"kind":"string","value":"Having a unique .git directory at the root of the project is a convenience. The .git directory can be anywhere in your project (or even outside) and it can be modified by setting GIT\\_DIR environment variable. But if you consider having it inside a subdirectory of your project, it is quite simple to delete it unwillingly which is much harder to do if it's at the root of the project."}}},{"rowIdx":67,"cells":{"qid":{"kind":"number","value":45010081,"string":"45,010,081"},"question":{"kind":"string","value":"I am following [Code for sending images using firebase](https://github.com/sancarbar/firebase-android.)\n\nI have configured the firebase storage url,database url ,database rule(true),sha1 placed google-services.json in app folder but when i debug the code the it(user) shows null value `FirebaseUser user = firebaseAuth.getCurrentUser();`\n.My code is given below:\n\n```\nimport android.content.Intent;\nimport android.os.Bundle;\nimport android.support.annotation.NonNull;\nimport android.support.annotation.Nullable;\nimport android.support.v7.app.AppCompatActivity;\nimport android.view.View;\nimport android.widget.Button;\nimport android.widget.Toast;\n\nimport com.google.firebase.auth.FirebaseAuth;\nimport com.google.firebase.auth.FirebaseUser;\n\nimport butterknife.Bind;\nimport butterknife.ButterKnife;\n\npublic class LoginActivity\n extends AppCompatActivity\n implements FirebaseAuth.AuthStateListener\n{\n\n @Bind( R.id.login_button )\n Button loginButton;\n\n FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();\n\n @Override\n protected void onCreate( @Nullable Bundle savedInstanceState )\n {\n super.onCreate( savedInstanceState );\n setContentView( R.layout.activity_login );\n ButterKnife.bind( this );\n }\n\n @Override\n public void onStart()\n {\n super.onStart();\n firebaseAuth.addAuthStateListener( this );\n verifyCurrentUserAndStartMainActivityIfLoggedIn();\n }\n\n @Override\n public void onStop()\n {\n super.onStop();\n firebaseAuth.removeAuthStateListener( this );\n }\n\n public void onLoginClicked( View view )\n {\n loginButton.setEnabled( false );\n firebaseAuth.signInAnonymously();\n }\n\n @Override\n public void onAuthStateChanged( @NonNull FirebaseAuth firebaseAuth )\n {\n verifyCurrentUserAndStartMainActivityIfLoggedIn();\n }\n\n private void verifyCurrentUserAndStartMainActivityIfLoggedIn()\n {\n FirebaseUser user = firebaseAuth.getCurrentUser();\n\n if ( user != null ) //HERE I AM GETTING \"user=null\" ??\n {\n\n startActivity( new Intent( this, MainActivity.class ) );\n Toast.makeText(this,\"Login success\",Toast.LENGTH_LONG).show();\n finish();\n }\n else\n {\n loginButton.setEnabled( true );\n }\n }\n\n}\n\n```\n\nAfter successfully login when (user !=null) the next activity displays now the sample url of next activity is\n\n```\n// StorageReference storageRef = storage.getReferenceFromUrl( \"gs://funchat-ef3ed.appspot.com\" );\n\n```\n\nand i have created new storage in firebase get the url is:\n\n```\n StorageReference storageRef = storage.getReferenceFromUrl( \"gs://fir-imagesending-1a8c1.appspot.com\");\n\n```\n\nWhen I use above url application crashes. The code is given below:\n\n```\npublic class MainActivity extends AppCompatActivity\n{\n\n static final int REQUEST_IMAGE_CAPTURE = 1;\n\n FirebaseDatabase database = FirebaseDatabase.getInstance();\n\n FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();\n\n DatabaseReference databaseReference = database.getReference( \"messages\" );\n\n FirebaseStorage storage = FirebaseStorage.getInstance();\n\n// StorageReference storageRef = storage.getReferenceFromUrl( \"gs://funchat-ef3ed.appspot.com\" );\n StorageReference storageRef = storage.getReferenceFromUrl( \"gs://fir-imagesending-1a8c1.appspot.com\");\n\n```\n\nI am unable to find where I am missing?"},"date":{"kind":"string","value":"2017/07/10"},"metadata":{"kind":"list like","value":["https://Stackoverflow.com/questions/45010081","https://Stackoverflow.com","https://Stackoverflow.com/users/8248471/"],"string":"[\n \"https://Stackoverflow.com/questions/45010081\",\n \"https://Stackoverflow.com\",\n \"https://Stackoverflow.com/users/8248471/\"\n]"},"response_j":{"kind":"string","value":"Your code seems to be far from oficial [firebase documentation](https://firebase.google.com/docs/auth/android/anonymous-auth)\n\n1. ensure you have anonymous login enabled in firebase console\n2. sign in anonymously with callback `mAuth.signInAnonymously().addOnCompleteListener`\n3. in `onComplete()` observe whether `Task.isSuccessful()` is true and if not what `task.getException()` return.\n4. and always follow official documentation not just somebody you have found on github\n\nIf you really want to know why your `FirebaseUser` is `null`, then read [firebase docs](https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseAuth)\n\nIf you post the exception I can help you."},"response_k":{"kind":"string","value":"You have to allow anonymous logins if you havn't and then `signInAnonymously()...`\nor you can make user login with google signin provided by firebase (for this first allow user signin with google in firebase console) and then just store all the instances as in singleton class. **will be much easy to do with much security**."}}},{"rowIdx":68,"cells":{"qid":{"kind":"number","value":53760622,"string":"53,760,622"},"question":{"kind":"string","value":"The following example is simplified. In my project I have a big `List(of String)` where I have to do some manipulations on the strings. For this I created a `Sub` where I do the manipulation and that should rewrite the Elements of the `List(of String)`. \n\n```\nModule Module1\n Sub Main()\n Dim myList As List(Of String) = New List(Of String)\n myList.Add(\"1Tom\")\n myList.Add(\"2Lisa\")\n 'Now I want apply a function to the List. As an example I created one that removes the first Letteer\n RemoveFirstChar(myList)\n For Each str As String In myList\n Console.Write(str)\n Next\n Console.Read()\n End Sub\n\n Sub RemoveFirstChar(ByRef myList As List(Of String))\n For Each str As String In myList\n str = str.Substring(2)\n Next\n End Sub\nEnd Module\n\n```\n\nThe string manipulation itself within the Sub works but it is not written into the initial List-Object. I actually thought that using `ByRef` would do this. Is it possible to do it this way and I just have a mistake or do I have to create a new `List(of String)` using a function and override the inital object. Like:\n\n```\nmyList = foo(myList)\n\n```\n\nIf both would work, what is more efficient? Since I have to do this on a List(of Strings) wiht few hundret thousand elements."},"date":{"kind":"string","value":"2018/12/13"},"metadata":{"kind":"list like","value":["https://Stackoverflow.com/questions/53760622","https://Stackoverflow.com","https://Stackoverflow.com/users/2377949/"],"string":"[\n \"https://Stackoverflow.com/questions/53760622\",\n \"https://Stackoverflow.com\",\n \"https://Stackoverflow.com/users/2377949/\"\n]"},"response_j":{"kind":"string","value":"Your have missed `[]` in the name value, it should be `name=\"shape[]\"`\n\n```js\n$('#form_filter input[name=\"shape[]\"][value=Round]').prop('checked', true);\n```\n\n```html\n\r\n
\r\n\r\n\r\n\r\n
\n```"},"response_k":{"kind":"string","value":"You should just use quotes inside the selector, ie:\n\n```\n$('#form_filter input[name=\"shape[]\"][value=\"Round\"]').length === 1 // true\n\n```\n\nOr:\n\n```\n$('#form_filter input[name=\"shape[]\"][value=\"Round\"]').prop('checked', true); // checks your specific checkbox\n\n```\n\n[jQuery docs on equals selector](https://api.jquery.com/attribute-equals-selector/) also state the following:\n\n> \n> attribute: An attribute name.\n> \n> \n> value: An attribute value. Can be either a valid identifier or a\n> *quoted string*.\n> \n> \n> \n\n---\n\nTest on the [JSFiddle](http://jsfiddle.net/1hrbfmqc/)."}}},{"rowIdx":69,"cells":{"qid":{"kind":"number","value":3047706,"string":"3,047,706"},"question":{"kind":"string","value":"In my textbook is stated: \nLet G be a finite-dimensional vector space of real functions in $R^D$.\nWhat is meant by \"*vector space of real functions*\"? \n\nI know what a vector space is, by I don't get how can real functions form vector space (The only vector spaces that I might see regarding a function are the vector space of the domain and codomain)\n\nPlease, if you are aware, provide me a tangible and intuitive example with the explanation, as I find examples extremely useful for understanding."},"date":{"kind":"string","value":"2018/12/20"},"metadata":{"kind":"list like","value":["https://math.stackexchange.com/questions/3047706","https://math.stackexchange.com","https://math.stackexchange.com/users/557201/"],"string":"[\n \"https://math.stackexchange.com/questions/3047706\",\n \"https://math.stackexchange.com\",\n \"https://math.stackexchange.com/users/557201/\"\n]"},"response_j":{"kind":"string","value":"$\\mathbb R^D$ is the set of all functions $f:D \\to \\mathbb R.$ If we define an addition $f+g$ and a scalar multiplication $ \\alpha f$ in this set by\n\n$(f+g)(x)=f(x)+g(x)$ and $( \\alpha f)(x)= \\alpha f(x)$,\n\nthen $\\mathbb R^D$ is a real vector space ( of functions)."},"response_k":{"kind":"string","value":"I'll offer a point of view that gives some concrete examples.\n\nAs people have mentioned, the only thing necessary to have a \"vector space\" is the ability to add objects together, and multiply them by scalars (subject to some special rules). We have this for functions that share a common domain and codomain. If we consider **all** functions with codomain $\\mathbb{R}$, and fixed codomain $D$, we get an infinite-dimensional vector space (unless $D$ is a finite set). This is what is usually called $\\mathbb{R}^{D}$. \n\nNow, if we want a **finite** dimensional vector space, what we are looking for is a subspace of $\\mathbb{R}^{D}$ that can be spanned by a finite set of functions. Here span is the normal linear algebra concept, where we are allowed to take linear combinations of the functions, e.g. the span of functions $f(x)$ and $g(x)$ would look like $\\{ af(x) + bg(x) \\ : \\ a,b \\in \\mathbb{R}\\}$.\n\nSome examples: \n\n1. If we take the set of constant functions $f(x) = c$ for $c \\in \\mathbb{R}$, this is a 1-dimensional vector space of functions, because any such function is just $c$ times the function $f(x) = 1$.\n2. If we take the set of polynomials of degree less than $n$, we get a vector space of dimensions $n+1$, for example the polynomials with degree less than 4 gives a 5-dimensional vector space with basis $\\{1,x,x^{2}, x^{3}, x^{4}\\}$.\n3. If we take linear combinations of $\\sin{x}$ and $\\cos{x}$, we get a vector space of dimension 2 containing functions of the form $\\{a\\sin{x}+b\\cos{x} \\ : \\ a,b \\in \\mathbb{R}\\}$ (it can be shown that $\\sin{x}$ and $\\cos{x}$ are not scalar multiples of each other, so are linearly independent)."}}},{"rowIdx":70,"cells":{"qid":{"kind":"number","value":1002395,"string":"1,002,395"},"question":{"kind":"string","value":"I want to add aliases to my network links to use them as short descriptions. I am configuring my interfaces using systemd-networkd, having systemd version 241 on a debian buster server.\n\nI've created the file\n`-rw-r--r-- 1 root root 68 Feb 9 12:53 /etc/systemd/network/ens19.link`\nwith the content:\n\n```\n[MATCH]\nMACAddress=7a:08:e8:12:fc:c7\n\n[LINK]\nAlias=myalias\n\n```\n\nI've tried to reboot the system, but the alias does not appear:\n\n```\n3: ens19: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000\n link/ether 7a:08:e8:12:fc:c7 brd ff:ff:ff:ff:ff:ff\n\n```\n\nDoing `ip l set ens19 alias myalias` gives the intended result:\n\n```\n3: ens19: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000\n link/ether 7a:08:e8:12:fc:c7 brd ff:ff:ff:ff:ff:ff\n alias myalias\n\n```\n\nHow can I achieve that using systemd-networkd?"},"date":{"kind":"string","value":"2020/02/09"},"metadata":{"kind":"list like","value":["https://serverfault.com/questions/1002395","https://serverfault.com","https://serverfault.com/users/527627/"],"string":"[\n \"https://serverfault.com/questions/1002395\",\n \"https://serverfault.com\",\n \"https://serverfault.com/users/527627/\"\n]"},"response_j":{"kind":"string","value":"I should have read [the manual](https://www.freedesktop.org/software/systemd/man/systemd.link.html) more carefully.\n\n> \n> The first (in lexical order) of the link files that matches a given device is applied. Note that a default file 99-default.link is shipped by the system. Any user-supplied .link should hence have a lexically earlier name to be considered at all.\n> \n> \n> \n\nRenaming `/etc/systemd/network/ens19.link` to `/etc/systemd/network/00-ens19.link` helped.\n\n`[MATCH]` should be `[Match]` and `[LINK]` should be `[Link]`.\n\nTo apply a changed .link file to the link I can reboot or run \n\n```\nudevadm test-builtin net_setup_link /sys/class/net/ens19\n\n```\n\n(Because .link files are processed by udev and not systemd-networkd, restarting systemd-networkd is insufficient.)"},"response_k":{"kind":"string","value":"As per [systemd.network](https://www.freedesktop.org/software/systemd/man/systemd.network.html) link aliases are not (yet?) supported."}}},{"rowIdx":71,"cells":{"qid":{"kind":"number","value":24615660,"string":"24,615,660"},"question":{"kind":"string","value":"Could someone please help me handle this issue in jQuery\n\nI have a requirement where I have two dropdowns: \n\n1. The no of floors of the flat (**numberOfFloors**)\n2. The flat where the user stays (**whichFloorYouStay**)\n\nI need to remove all the invalid options from the second dropdown. How do I achieve this?\n\nFor example: \nIf a user select the **numberOfFloors** option as 3, then I should remove options 4 and 5 from **whichFloorYouStay** dropdown and just load 1,2,3 as **whichFloorYouStay** options.\n\nSimilarly, if a user select the **numberOfFloors** option as 1, then I should remove options 2,3,4,5 from **whichFloorYouStay** dropdown and just load 1 as **whichFloorYouStay** option.\n\nPlease find my JSBin link: \n\n"},"date":{"kind":"string","value":"2014/07/07"},"metadata":{"kind":"list like","value":["https://Stackoverflow.com/questions/24615660","https://Stackoverflow.com","https://Stackoverflow.com/users/3673638/"],"string":"[\n \"https://Stackoverflow.com/questions/24615660\",\n \"https://Stackoverflow.com\",\n \"https://Stackoverflow.com/users/3673638/\"\n]"},"response_j":{"kind":"string","value":"I am not sure whether you can do it using css.Anyway you can do this using javascript. The code will be as follows :\n\n```\n String.prototype.chunk = function(n) {\n var space = [];\n for(var i=0, len=this.length; i < len; i += n) {\n space.push(this.substr(i, n))\n }\n return space\n };\n\n\"0102030405\".chunk(2).join(' ');\n\n```\n\nCheck [Fiddle](http://jsfiddle.net/mijoemathew/Fysr4/)"},"response_k":{"kind":"string","value":"It cannot be done in CSS, because there is no selector that would refer to, say, the 3rd character in the content of an element or the the first two characters. CSS operates on elements and pseudo-elements, and no currently defined pseudo-element is suitable for this.\n\nIf possible, the content should be modified server-side or, if that’s not possible, with client-side JavaScript so that either the character pairs appear as elements or there are space characters between them, e.g. `01 02 03 04 05`. In the latter case, you can use `word-spacing` (probably with a negative value) to tune the amount of spacing."}}},{"rowIdx":72,"cells":{"qid":{"kind":"number","value":19089163,"string":"19,089,163"},"question":{"kind":"string","value":"I am using the RSA python package to encrypt a message and try to pass it to a PHP site to decrypt. See below:\n\n```\nmessage = rsa.encrypt('abc', pubkey)\nprint message\nprint type(message)\n\n```\n\nWhat I get is some encrypted text\n\n```\nq??$$??kK?Y??p?[e?[??f???x??s!?s?>?z?*y?p?????????分?\n? ???({u????NH?B???N?%?@5|?~?????\\U?.??r?Y?q\n\n\n```\n\nWhat's the best way to pass it to other languages to decrypt?"},"date":{"kind":"string","value":"2013/09/30"},"metadata":{"kind":"list like","value":["https://Stackoverflow.com/questions/19089163","https://Stackoverflow.com","https://Stackoverflow.com/users/342553/"],"string":"[\n \"https://Stackoverflow.com/questions/19089163\",\n \"https://Stackoverflow.com\",\n \"https://Stackoverflow.com/users/342553/\"\n]"},"response_j":{"kind":"string","value":"The \"-D\" prefix in the argument means that it's a *system property*. \n\nA system property is defined like this in():\n\n> \n> A system property is a key/value pair that the Java runtime defines to\n> describe the user, system environment, and Java system. The runtime\n> defines and uses a set of default system properties. Other properties\n> can be made available to a Java program via the -D command line option\n> to the Java interpreter.\n> \n> \n>"},"response_k":{"kind":"string","value":"mvn eclipse:eclipse -Dwtpversion=2.0 makes it a maven project that can be run from eclipse"}}},{"rowIdx":73,"cells":{"qid":{"kind":"number","value":20505869,"string":"20,505,869"},"question":{"kind":"string","value":"For example, there is a list:\n\n`s = [1,2,3,4]` \n\nfrom which we want to get new list\n\n`s1 = [1.5, 2.5, 3.5]` (length was reduced).\n\nHow to compute this with the most efficient way in Python (e.g. map, generator comprehensions)?\n\n*Update:* \nOK, this example was very artificial. Accidently, I'm trying to find the fastest way to compute new list from old. And it will be interesting for me to see optimal ways (minor memory usage, for example)"},"date":{"kind":"string","value":"2013/12/10"},"metadata":{"kind":"list like","value":["https://Stackoverflow.com/questions/20505869","https://Stackoverflow.com","https://Stackoverflow.com/users/2938167/"],"string":"[\n \"https://Stackoverflow.com/questions/20505869\",\n \"https://Stackoverflow.com\",\n \"https://Stackoverflow.com/users/2938167/\"\n]"},"response_j":{"kind":"string","value":"```\nalist = [(s[i]+s[i+1])/2 for i in range(len(s)-1)]\n\n```\n\nwell, i dont know how efficient it is."},"response_k":{"kind":"string","value":"I am guessing that the fastest way, if you have a large list, is the following:\n\n```\nimport numpy as np\nkernel = np.array([0.5, 0.5]) # convolution kernel\nmy_list = range(100000) # lots of data\narr = np.array(my_list) # make it an array\nresult = np.convolve(arr, kernel, 'valid') # convolve\n\n```\n\nThis uses convolution in the numeric python package, which should be really fast. I would love to see if someone can find a faster solution :)\n\n**Edit** Did some benchmarking, and for lists of size 1000+ the numpy version is faster than Twisted Meadows version."}}},{"rowIdx":74,"cells":{"qid":{"kind":"number","value":29784077,"string":"29,784,077"},"question":{"kind":"string","value":"I'm trying to write a custom iterator in spacebars (I'm using meteor 1.1.3). The iterator is to be a sequential for loop (basically to replace my usage of #each when needed since I believe #each is not guaranteed to be sequential in its iteration).\n\nI have tried the following:\n\nIn lib - \n\n```\nUI.registerHelper 'sequentialFor', () ->\n ret = \"\"\n for i in [0...@.length]\n id = @[i]\n ret = ret + Template.noop\n ret\n\n```\n\nnoop.html -\n\n```\n