devngho/the-stack-mini-edu · Datasets at Fast360
{
// 获取包含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 content += ''\n content = inlineCss(content, style + config.extraCss, config.inlineOpts)\n } else {\n content = `
${content}
`\n content = inlineCss(content, style, config.inlineOpts)\n }\n\n res.send(content)\n})\n\napp.listen(process.env.PORT || 3000)\n"},"avg_line_length":{"kind":"number","value":33.6883116883,"string":"33.688312"},"max_line_length":{"kind":"number","value":106,"string":"106"},"alphanum_fraction":{"kind":"number","value":0.6723207402,"string":"0.672321"},"score":{"kind":"number","value":3.140625,"string":"3.140625"}}},{"rowIdx":909,"cells":{"hexsha":{"kind":"string","value":"5f5df4c16e3cbba91cabd10a1877c24964949db2"},"size":{"kind":"number","value":2915,"string":"2,915"},"ext":{"kind":"string","value":"ts"},"lang":{"kind":"string","value":"TypeScript"},"max_stars_repo_path":{"kind":"string","value":"src/tests/utilities.test.ts"},"max_stars_repo_name":{"kind":"string","value":"jmgrady/TheCombine"},"max_stars_repo_head_hexsha":{"kind":"string","value":"4645d891f4825458553b94119a7b5731bed715d3"},"max_stars_repo_licenses":{"kind":"list like","value":["MIT"],"string":"[\n \"MIT\"\n]"},"max_stars_count":{"kind":"null"},"max_stars_repo_stars_event_min_datetime":{"kind":"null"},"max_stars_repo_stars_event_max_datetime":{"kind":"null"},"max_issues_repo_path":{"kind":"string","value":"src/tests/utilities.test.ts"},"max_issues_repo_name":{"kind":"string","value":"jmgrady/TheCombine"},"max_issues_repo_head_hexsha":{"kind":"string","value":"4645d891f4825458553b94119a7b5731bed715d3"},"max_issues_repo_licenses":{"kind":"list like","value":["MIT"],"string":"[\n \"MIT\"\n]"},"max_issues_count":{"kind":"null"},"max_issues_repo_issues_event_min_datetime":{"kind":"null"},"max_issues_repo_issues_event_max_datetime":{"kind":"null"},"max_forks_repo_path":{"kind":"string","value":"src/tests/utilities.test.ts"},"max_forks_repo_name":{"kind":"string","value":"jmgrady/TheCombine"},"max_forks_repo_head_hexsha":{"kind":"string","value":"4645d891f4825458553b94119a7b5731bed715d3"},"max_forks_repo_licenses":{"kind":"list like","value":["MIT"],"string":"[\n \"MIT\"\n]"},"max_forks_count":{"kind":"null"},"max_forks_repo_forks_event_min_datetime":{"kind":"null"},"max_forks_repo_forks_event_max_datetime":{"kind":"null"},"content":{"kind":"string","value":"import * as utilities from \"utilities\";\n\ndescribe(\"utilities\", () => {\n describe(\"quicksort\", () => {\n const compareItem = (input: number) => {\n return input;\n };\n\n const numbers: number[] = [];\n for (let i = 0; i < 25; i++) numbers.push(Math.random());\n\n it(\"orders properly\", () => {\n const sortedNums = utilities.quicksort(numbers, compareItem);\n for (let i = 1; i < sortedNums.length; i++)\n expect(sortedNums[i - 1]).toBeLessThanOrEqual(sortedNums[i]);\n });\n });\n\n describe(\"getNowDateTimeString\", () => {\n // This tests will fail intermittently if there is a bug with the 0-prepend\n it(\"returns string of correct length\", () => {\n const expectedLength = \"YYYY-MM-DD_hh-mm-ss\".length;\n expect(utilities.getNowDateTimeString().length).toBe(expectedLength);\n });\n });\n\n describe(\"LevenshteinDistance\", () => {\n let finder: utilities.LevenshteinDistance;\n const testParams: utilities.LevenshteinDistParams = {\n delCost: 3,\n insCost: 4,\n subCost: 5,\n };\n\n beforeEach(() => {\n finder = new utilities.LevenshteinDistance(testParams);\n });\n\n describe(\"getDistance\", () => {\n const baseWord = \"testing\";\n\n test(\"with empty word\", () => {\n expect(finder.getDistance(\"\", \"\")).toEqual(0);\n expect(finder.getDistance(baseWord, \"\")).toEqual(\n baseWord.length * testParams.delCost\n );\n expect(finder.getDistance(\"\", baseWord)).toEqual(\n baseWord.length * testParams.insCost\n );\n });\n\n const similarCases: [string, string, number][] = [\n [\"same word\", baseWord, 0],\n [\"1 deletion\", \"testin\", testParams.delCost],\n [\"1 insertion\", \"testings\", testParams.insCost],\n [\"1 substitution\", \"tasting\", testParams.subCost],\n [\"2 substitutions\", \"tossing\", 2 * testParams.subCost],\n [\n \"1 insertion, 1 deletion\",\n \"teasing\",\n testParams.insCost + testParams.delCost,\n ],\n [\n \"1 insertion, 1 substitution\",\n \"toasting\",\n testParams.insCost + testParams.subCost,\n ],\n ];\n test.each(similarCases)(\n \"with similar word: %p\",\n (_description: string, secondWord: string, expectedDist: number) => {\n expect(finder.getDistance(baseWord, secondWord)).toEqual(\n expectedDist\n );\n }\n );\n\n test(\"with much different words\", () => {\n const diffWord = \"QQQ\";\n expect(finder.getDistance(diffWord, baseWord)).toEqual(\n diffWord.length * testParams.subCost +\n (baseWord.length - diffWord.length) * testParams.insCost\n );\n expect(finder.getDistance(baseWord, diffWord)).toEqual(\n diffWord.length * testParams.subCost +\n (baseWord.length - diffWord.length) * testParams.delCost\n );\n });\n });\n });\n});\n"},"avg_line_length":{"kind":"number","value":31.6847826087,"string":"31.684783"},"max_line_length":{"kind":"number","value":79,"string":"79"},"alphanum_fraction":{"kind":"number","value":0.5780445969,"string":"0.578045"},"score":{"kind":"number","value":3.359375,"string":"3.359375"}}},{"rowIdx":910,"cells":{"hexsha":{"kind":"string","value":"dfd7c4d2364f15422ade24e6579947af63f87ec7"},"size":{"kind":"number","value":1585,"string":"1,585"},"ext":{"kind":"string","value":"ts"},"lang":{"kind":"string","value":"TypeScript"},"max_stars_repo_path":{"kind":"string","value":"backend/src/connect.database.ts"},"max_stars_repo_name":{"kind":"string","value":"ExiledNarwal28/gif-3112-project"},"max_stars_repo_head_hexsha":{"kind":"string","value":"806c697705c13d813a85dd643bd733dbd39af96d"},"max_stars_repo_licenses":{"kind":"list like","value":["MIT"],"string":"[\n \"MIT\"\n]"},"max_stars_count":{"kind":"number","value":1,"string":"1"},"max_stars_repo_stars_event_min_datetime":{"kind":"string","value":"2021-11-12T06:58:38.000Z"},"max_stars_repo_stars_event_max_datetime":{"kind":"string","value":"2021-11-12T06:58:38.000Z"},"max_issues_repo_path":{"kind":"string","value":"backend/src/connect.database.ts"},"max_issues_repo_name":{"kind":"string","value":"ExiledNarwal28/gif-3112-project"},"max_issues_repo_head_hexsha":{"kind":"string","value":"806c697705c13d813a85dd643bd733dbd39af96d"},"max_issues_repo_licenses":{"kind":"list like","value":["MIT"],"string":"[\n \"MIT\"\n]"},"max_issues_count":{"kind":"null"},"max_issues_repo_issues_event_min_datetime":{"kind":"null"},"max_issues_repo_issues_event_max_datetime":{"kind":"null"},"max_forks_repo_path":{"kind":"string","value":"backend/src/connect.database.ts"},"max_forks_repo_name":{"kind":"string","value":"ExiledNarwal28/gif-3112-project"},"max_forks_repo_head_hexsha":{"kind":"string","value":"806c697705c13d813a85dd643bd733dbd39af96d"},"max_forks_repo_licenses":{"kind":"list like","value":["MIT"],"string":"[\n \"MIT\"\n]"},"max_forks_count":{"kind":"null"},"max_forks_repo_forks_event_min_datetime":{"kind":"null"},"max_forks_repo_forks_event_max_datetime":{"kind":"null"},"content":{"kind":"string","value":"import mongoose from 'mongoose';\nimport { logger } from './middlewares/logger';\n\nconst mongoURL = process.env.MONGO_URL || '';\n\nconst mongoOptions = {\n useFindAndModify: false,\n useNewUrlParser: true,\n useUnifiedTopology: true,\n user: process.env.MONGO_USERNAME,\n pass: process.env.MONGO_PASSWORD,\n};\n\nconst db = mongoose.connection;\n\ndb.on('connecting', () => logger.info('Connecting to MongoDB...'));\n\ndb.on('error', (error) =>\n logger.error(`Error in MongoDB connection : ${error}`),\n);\ndb.on('connected', () => logger.info('MongoDB connected!'));\n\ndb.once('open', async () => {\n logger.info('MongoDB connection opened!');\n});\n\ndb.on('reconnected', () => logger.info('MongoDB reconnected!'));\n\ndb.on('disconnected', () => {\n logger.info('MongoDB disconnected!');\n retryConnectionAfterTimeout();\n});\n\nconst MAX_ATTEMPTS = 10;\nconst FACTOR = 1.5;\nconst DEFAULT_RETRY_TIMEOUT = 5000;\nconst DEFAULT_ATTEMPTS = 0;\n\nlet retryTimeout = DEFAULT_RETRY_TIMEOUT;\nlet attempts = DEFAULT_ATTEMPTS;\n\nconst retryConnectionAfterTimeout = () => {\n if (attempts < MAX_ATTEMPTS) {\n logger.info(`Retrying connection in ${retryTimeout / 1000} seconds`);\n setTimeout(connectDatabase, retryTimeout);\n\n retryTimeout *= FACTOR;\n attempts++;\n } else {\n logger.info(`Max connection attempts (${MAX_ATTEMPTS}) reached!`);\n }\n};\n\nexport function connectDatabase() {\n mongoose\n .connect(mongoURL, mongoOptions)\n .then(() => {\n retryTimeout = DEFAULT_RETRY_TIMEOUT;\n attempts = DEFAULT_ATTEMPTS;\n })\n .catch(() => {\n retryConnectionAfterTimeout();\n });\n}\n"},"avg_line_length":{"kind":"number","value":24.3846153846,"string":"24.384615"},"max_line_length":{"kind":"number","value":73,"string":"73"},"alphanum_fraction":{"kind":"number","value":0.680126183,"string":"0.680126"},"score":{"kind":"number","value":3.015625,"string":"3.015625"}}},{"rowIdx":911,"cells":{"hexsha":{"kind":"string","value":"c36bc166ac8c5e32810efdfb68416109d184994a"},"size":{"kind":"number","value":1233,"string":"1,233"},"ext":{"kind":"string","value":"go"},"lang":{"kind":"string","value":"Go"},"max_stars_repo_path":{"kind":"string","value":"st600/fuzz.go"},"max_stars_repo_name":{"kind":"string","value":"larixsource/stgps"},"max_stars_repo_head_hexsha":{"kind":"string","value":"03af5b868f238dd04a10c161038759036daee6ac"},"max_stars_repo_licenses":{"kind":"list like","value":["MIT"],"string":"[\n \"MIT\"\n]"},"max_stars_count":{"kind":"number","value":7,"string":"7"},"max_stars_repo_stars_event_min_datetime":{"kind":"string","value":"2017-05-17T20:12:49.000Z"},"max_stars_repo_stars_event_max_datetime":{"kind":"string","value":"2021-07-12T21:41:48.000Z"},"max_issues_repo_path":{"kind":"string","value":"st600/fuzz.go"},"max_issues_repo_name":{"kind":"string","value":"larixsource/stgps"},"max_issues_repo_head_hexsha":{"kind":"string","value":"03af5b868f238dd04a10c161038759036daee6ac"},"max_issues_repo_licenses":{"kind":"list like","value":["MIT"],"string":"[\n \"MIT\"\n]"},"max_issues_count":{"kind":"null"},"max_issues_repo_issues_event_min_datetime":{"kind":"null"},"max_issues_repo_issues_event_max_datetime":{"kind":"null"},"max_forks_repo_path":{"kind":"string","value":"st600/fuzz.go"},"max_forks_repo_name":{"kind":"string","value":"larixsource/stgps"},"max_forks_repo_head_hexsha":{"kind":"string","value":"03af5b868f238dd04a10c161038759036daee6ac"},"max_forks_repo_licenses":{"kind":"list like","value":["MIT"],"string":"[\n \"MIT\"\n]"},"max_forks_count":{"kind":"number","value":3,"string":"3"},"max_forks_repo_forks_event_min_datetime":{"kind":"string","value":"2016-11-29T23:30:08.000Z"},"max_forks_repo_forks_event_max_datetime":{"kind":"string","value":"2018-12-04T13:19:58.000Z"},"content":{"kind":"string","value":"package st600\n\nfunc Fuzz(data []byte) int {\n\tp := ParseBytes(data, ParserOpts{})\n\n\tvar results []int\n\tfor p.Next() {\n\t\tframe := p.Msg()\n\t\tif frame == nil {\n\t\t\tpanic(\"nil frame\")\n\t\t}\n\t\tif len(frame.Frame) == 0 {\n\t\t\tpanic(\"empty raw frame\")\n\t\t}\n\t\tif frame.ParsingError != nil {\n\t\t\tresults = append(results, 0)\n\t\t\tcontinue\n\t\t}\n\t\tswitch frame.Type {\n\t\tcase STTReport:\n\t\t\tif frame.STT == nil {\n\t\t\t\tpanic(\"nil STT\")\n\t\t\t}\n\t\tcase EMGReport:\n\t\t\tif frame.EMG == nil {\n\t\t\t\tpanic(\"nil EMG\")\n\t\t\t}\n\t\tcase EVTReport:\n\t\t\tif frame.EVT == nil {\n\t\t\t\tpanic(\"nil EVT\")\n\t\t\t}\n\t\tcase ALTReport:\n\t\t\tif frame.ALT == nil {\n\t\t\t\tpanic(\"nil ALT\")\n\t\t\t}\n\t\tcase ALVReport:\n\t\t\tif frame.ALV == nil {\n\t\t\t\tpanic(\"nil ALV\")\n\t\t\t}\n\t\tcase UEXReport:\n\t\t\tif frame.UEX == nil {\n\t\t\t\tpanic(\"nil UEX\")\n\t\t\t}\n\t\tcase UnknownMsg:\n\t\tdefault:\n\t\t\tpanic(\"invalid Type\")\n\t\t}\n\n\t\t// good frame\n\t\tresults = append(results, 1)\n\t}\n\n\t// count results (zeroes and ones)\n\tzeroCount := 0\n\toneCount := 0\n\tfor _, r := range results {\n\t\tswitch r {\n\t\tcase 0:\n\t\t\tzeroCount++\n\t\tcase 1:\n\t\t\toneCount++\n\t\tdefault:\n\t\t\tpanic(\"fuzz programming error\")\n\t\t}\n\t}\n\n\tswitch {\n\tcase oneCount == 0:\n\t\treturn 0\n\tcase zeroCount == 0 || zeroCount == 1: // at most one error permitted\n\t\treturn 1\n\tdefault:\n\t\treturn 0\n\t}\n}\n"},"avg_line_length":{"kind":"number","value":16.2236842105,"string":"16.223684"},"max_line_length":{"kind":"number","value":70,"string":"70"},"alphanum_fraction":{"kind":"number","value":0.5831305758,"string":"0.583131"},"score":{"kind":"number","value":3.03125,"string":"3.03125"}}},{"rowIdx":912,"cells":{"hexsha":{"kind":"string","value":"a1a6cf56c78ce242de3be9a964be2f1ff6b74f8a"},"size":{"kind":"number","value":2736,"string":"2,736"},"ext":{"kind":"string","value":"go"},"lang":{"kind":"string","value":"Go"},"max_stars_repo_path":{"kind":"string","value":"cmd/ports.go"},"max_stars_repo_name":{"kind":"string","value":"rmohr/cli"},"max_stars_repo_head_hexsha":{"kind":"string","value":"a95a4b96a0c93899e2e6c3f1ef0ce911b118a382"},"max_stars_repo_licenses":{"kind":"list like","value":["Apache-2.0"],"string":"[\n \"Apache-2.0\"\n]"},"max_stars_count":{"kind":"null"},"max_stars_repo_stars_event_min_datetime":{"kind":"null"},"max_stars_repo_stars_event_max_datetime":{"kind":"null"},"max_issues_repo_path":{"kind":"string","value":"cmd/ports.go"},"max_issues_repo_name":{"kind":"string","value":"rmohr/cli"},"max_issues_repo_head_hexsha":{"kind":"string","value":"a95a4b96a0c93899e2e6c3f1ef0ce911b118a382"},"max_issues_repo_licenses":{"kind":"list like","value":["Apache-2.0"],"string":"[\n \"Apache-2.0\"\n]"},"max_issues_count":{"kind":"null"},"max_issues_repo_issues_event_min_datetime":{"kind":"null"},"max_issues_repo_issues_event_max_datetime":{"kind":"null"},"max_forks_repo_path":{"kind":"string","value":"cmd/ports.go"},"max_forks_repo_name":{"kind":"string","value":"rmohr/cli"},"max_forks_repo_head_hexsha":{"kind":"string","value":"a95a4b96a0c93899e2e6c3f1ef0ce911b118a382"},"max_forks_repo_licenses":{"kind":"list like","value":["Apache-2.0"],"string":"[\n \"Apache-2.0\"\n]"},"max_forks_count":{"kind":"null"},"max_forks_repo_forks_event_min_datetime":{"kind":"null"},"max_forks_repo_forks_event_max_datetime":{"kind":"null"},"content":{"kind":"string","value":"package cmd\n\nimport (\n\t\"fmt\"\n\t\"github.com/docker/docker/api/types\"\n\t\"github.com/docker/docker/client\"\n\t\"github.com/docker/go-connections/nat\"\n\t\"github.com/rmohr/cli/docker\"\n\t\"github.com/spf13/cobra\"\n\t\"strconv\"\n)\n\nconst (\n\tPORT_SSH = 2201\n\tPORT_REGISTRY = 5000\n\tPORT_OCP = 8443\n\tPORT_K8S = 6443\n\tPORT_VNC = 5901\n\n\tPORT_NAME_SSH = \"ssh\"\n\tPORT_NAME_OCP = \"ocp\"\n\tPORT_NAME_REGISTRY = \"registry\"\n\tPORT_NAME_K8S = \"k8s\"\n\tPORT_NAME_VNC = \"vnc\"\n)\n\nfunc NewPortCommand() *cobra.Command {\n\n\tport := &cobra.Command{\n\t\tUse: \"ports\",\n\t\tShort: \"ports shows exposed ports of the cluster\",\n\t\tLong: `ports shows exposed ports of the cluster\n\nIf no port name is specified, all exposed ports are printed.\nIf an extra port name is specified, only the exposed port is printed.\n\nKnown port names are 'ssh', 'registry', 'ocp' and 'k8s'.\n`,\n\t\tRunE: ports,\n\t\tArgs: func(cmd *cobra.Command, args []string) error {\n\t\t\tif len(args) > 1 {\n\t\t\t\treturn fmt.Errorf(\"only one port name can be specified at once\")\n\t\t\t}\n\n\t\t\tif len(args) == 1 {\n\t\t\t\tswitch args[0] {\n\t\t\t\tcase PORT_NAME_SSH, PORT_NAME_K8S, PORT_NAME_OCP, PORT_NAME_REGISTRY, PORT_NAME_VNC:\n\t\t\t\t\treturn nil\n\t\t\t\tdefault:\n\t\t\t\t\treturn fmt.Errorf(\"unknown port name %s\", args[0])\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn nil\n\t\t},\n\t}\n\treturn port\n}\n\nfunc ports(cmd *cobra.Command, args []string) error {\n\n\tprefix, err := cmd.Flags().GetString(\"prefix\")\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tcli, err := client.NewEnvClient()\n\tif err != nil {\n\t\treturn err\n\t}\n\tcontainer, err := docker.GetDDNSMasqContainer(cli, prefix)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tportName := \"\"\n\tif len(args) > 0 {\n\t\tportName = args[0]\n\t}\n\n\tif portName != \"\" {\n\t\terr = nil\n\t\tswitch portName {\n\t\tcase PORT_NAME_SSH:\n\t\t\terr = printPort(PORT_SSH, container.Ports)\n\t\tcase PORT_NAME_K8S:\n\t\t\terr = printPort(PORT_K8S, container.Ports)\n\t\tcase PORT_NAME_REGISTRY:\n\t\t\terr = printPort(PORT_REGISTRY, container.Ports)\n\t\tcase PORT_NAME_OCP:\n\t\t\terr = printPort(PORT_OCP, container.Ports)\n\t\tcase PORT_NAME_VNC:\n\t\t\terr = printPort(PORT_VNC, container.Ports)\n\t\t}\n\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t} else {\n\t\tfor _, p := range container.Ports {\n\t\t\tfmt.Printf(\"%d/%s -> %s:%d\\n\", p.PrivatePort, p.Type, p.IP, p.PublicPort)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc getPort(port uint16, ports []types.Port) (uint16, error) {\n\tfor _, p := range ports {\n\t\tif p.PrivatePort == port {\n\t\t\treturn p.PublicPort, nil\n\t\t}\n\t}\n\treturn 0, fmt.Errorf(\"port is not exposed\")\n}\n\nfunc printPort(port uint16, ports []types.Port) error {\n\tp, err := getPort(port, ports)\n\tif err != nil {\n\t\treturn err\n\t}\n\tfmt.Println(p)\n\treturn nil\n}\n\nfunc tcpPortOrDie(port int) nat.Port {\n\tp, err := nat.NewPort(\"tcp\", strconv.Itoa(port))\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn p\n}\n"},"avg_line_length":{"kind":"number","value":20.5714285714,"string":"20.571429"},"max_line_length":{"kind":"number","value":88,"string":"88"},"alphanum_fraction":{"kind":"number","value":0.6549707602,"string":"0.654971"},"score":{"kind":"number","value":3.125,"string":"3.125"}}},{"rowIdx":913,"cells":{"hexsha":{"kind":"string","value":"bd3a662fb349989868d51eb2243cb72e1eac5b28"},"size":{"kind":"number","value":2124,"string":"2,124"},"ext":{"kind":"string","value":"rs"},"lang":{"kind":"string","value":"Rust"},"max_stars_repo_path":{"kind":"string","value":"web-server/sgx-wallet-impl/src/schema/types.rs"},"max_stars_repo_name":{"kind":"string","value":"ntls-io/nautilus-wallet"},"max_stars_repo_head_hexsha":{"kind":"string","value":"31a6a534c920d58548a8ac5869b3cb918d3b7c11"},"max_stars_repo_licenses":{"kind":"list like","value":["Apache-2.0"],"string":"[\n \"Apache-2.0\"\n]"},"max_stars_count":{"kind":"number","value":1,"string":"1"},"max_stars_repo_stars_event_min_datetime":{"kind":"string","value":"2022-01-30T03:54:55.000Z"},"max_stars_repo_stars_event_max_datetime":{"kind":"string","value":"2022-01-30T03:54:55.000Z"},"max_issues_repo_path":{"kind":"string","value":"web-server/sgx-wallet-impl/src/schema/types.rs"},"max_issues_repo_name":{"kind":"string","value":"ntls-io/nautilus-wallet"},"max_issues_repo_head_hexsha":{"kind":"string","value":"31a6a534c920d58548a8ac5869b3cb918d3b7c11"},"max_issues_repo_licenses":{"kind":"list like","value":["Apache-2.0"],"string":"[\n \"Apache-2.0\"\n]"},"max_issues_count":{"kind":"number","value":32,"string":"32"},"max_issues_repo_issues_event_min_datetime":{"kind":"string","value":"2021-11-15T08:43:10.000Z"},"max_issues_repo_issues_event_max_datetime":{"kind":"string","value":"2022-03-20T22:35:56.000Z"},"max_forks_repo_path":{"kind":"string","value":"web-server/sgx-wallet-impl/src/schema/types.rs"},"max_forks_repo_name":{"kind":"string","value":"ntls-io/nautilus-wallet"},"max_forks_repo_head_hexsha":{"kind":"string","value":"31a6a534c920d58548a8ac5869b3cb918d3b7c11"},"max_forks_repo_licenses":{"kind":"list like","value":["Apache-2.0"],"string":"[\n \"Apache-2.0\"\n]"},"max_forks_count":{"kind":"number","value":2,"string":"2"},"max_forks_repo_forks_event_min_datetime":{"kind":"string","value":"2021-11-21T19:19:08.000Z"},"max_forks_repo_forks_event_max_datetime":{"kind":"string","value":"2021-11-22T09:17:01.000Z"},"content":{"kind":"string","value":"//! Supporting data types.\n\nuse std::boxed::Box;\nuse std::prelude::v1::String;\n\nuse ripple_keypairs::{Algorithm, EntropyArray};\nuse serde::{Deserialize, Serialize};\n\npub type Bytes = Box<[u8]>;\n\n/// Nautilus Wallet ID.\npub type WalletId = String;\n\n/// A wallet owner's authenticating PIN.\npub type WalletPin = String;\n\n/// Algorand account seed, as bytes.\npub type AlgorandAccountSeedBytes = [u8; 32];\n\n/// Algorand account address, as bytes.\npub type AlgorandAddressBytes = [u8; 32];\n\n/// Algorand account address, as base32 with checksum.\npub type AlgorandAddressBase32 = String;\n\n/// XRPL key type (signing algorithm).\n///\n/// Docs: \n#[derive(Copy, Clone, Eq, PartialEq, Debug)] // core\n#[derive(Deserialize, Serialize)] // serde\n#[serde(rename_all = \"lowercase\")]\npub enum XrplKeyType {\n Secp256k1,\n Ed25519,\n}\n\n/// Default to `secp256k1`, like the XRP Ledger.\nimpl Default for XrplKeyType {\n fn default() -> Self {\n Self::Secp256k1\n }\n}\n\n// Convert between our representation and ripple-keypairs.\n\n/// Convert from `&Algorithm`, as used by ripple-keypairs.\nimpl From<&Algorithm> for XrplKeyType {\n fn from(algorithm: &Algorithm) -> Self {\n match algorithm {\n Algorithm::Secp256k1 => Self::Secp256k1,\n Algorithm::Ed25519 => Self::Ed25519,\n }\n }\n}\n\n/// Convert to `&'static Algorithm`, as expected by ripple-keypairs.\nimpl From for &'static Algorithm {\n fn from(key_type: XrplKeyType) -> Self {\n match key_type {\n XrplKeyType::Secp256k1 => &Algorithm::Secp256k1,\n XrplKeyType::Ed25519 => &Algorithm::Ed25519,\n }\n }\n}\n\n/// XRP account seed, as bytes.\npub type XrplAccountSeedBytes = EntropyArray;\n\n/// XRP account address, as base58 with checksum (\"Base58Check\").\n///\n/// Docs: \npub type XrplAddressBase58 = String;\n\n/// XRP public key, as a hexadecimal string. Used to prepare unsigned transactions.\n///\n/// Docs: \npub type XrplPublicKeyHex = String;\n"},"avg_line_length":{"kind":"number","value":27.2307692308,"string":"27.230769"},"max_line_length":{"kind":"number","value":83,"string":"83"},"alphanum_fraction":{"kind":"number","value":0.6822033898,"string":"0.682203"},"score":{"kind":"number","value":3.09375,"string":"3.09375"}}},{"rowIdx":914,"cells":{"hexsha":{"kind":"string","value":"653e59fcbdd6ab10a8f9cfbeb5d59f5f53315a37"},"size":{"kind":"number","value":6114,"string":"6,114"},"ext":{"kind":"string","value":"py"},"lang":{"kind":"string","value":"Python"},"max_stars_repo_path":{"kind":"string","value":"src/trainer/transformations.py"},"max_stars_repo_name":{"kind":"string","value":"tiborkubik/Robust-Teeth-Detection-in-3D-Dental-Scans-by-Automated-Multi-View-Landmarking"},"max_stars_repo_head_hexsha":{"kind":"string","value":"c7d9fa29b3b94ea786da5f4ec11a11520c1b882a"},"max_stars_repo_licenses":{"kind":"list like","value":["MIT"],"string":"[\n \"MIT\"\n]"},"max_stars_count":{"kind":"number","value":2,"string":"2"},"max_stars_repo_stars_event_min_datetime":{"kind":"string","value":"2022-02-20T23:45:47.000Z"},"max_stars_repo_stars_event_max_datetime":{"kind":"string","value":"2022-03-14T07:36:53.000Z"},"max_issues_repo_path":{"kind":"string","value":"src/trainer/transformations.py"},"max_issues_repo_name":{"kind":"string","value":"tiborkubik/Robust-Teeth-Detection-in-3D-Dental-Scans-by-Automated-Multi-View-Landmarking"},"max_issues_repo_head_hexsha":{"kind":"string","value":"c7d9fa29b3b94ea786da5f4ec11a11520c1b882a"},"max_issues_repo_licenses":{"kind":"list like","value":["MIT"],"string":"[\n \"MIT\"\n]"},"max_issues_count":{"kind":"null"},"max_issues_repo_issues_event_min_datetime":{"kind":"null"},"max_issues_repo_issues_event_max_datetime":{"kind":"null"},"max_forks_repo_path":{"kind":"string","value":"src/trainer/transformations.py"},"max_forks_repo_name":{"kind":"string","value":"tiborkubik/Robust-Teeth-Detection-in-3D-Dental-Scans-by-Automated-Multi-View-Landmarking"},"max_forks_repo_head_hexsha":{"kind":"string","value":"c7d9fa29b3b94ea786da5f4ec11a11520c1b882a"},"max_forks_repo_licenses":{"kind":"list like","value":["MIT"],"string":"[\n \"MIT\"\n]"},"max_forks_count":{"kind":"null"},"max_forks_repo_forks_event_min_datetime":{"kind":"null"},"max_forks_repo_forks_event_max_datetime":{"kind":"null"},"content":{"kind":"string","value":"\"\"\"\n :filename transformations.py\n :author Tibor Kubik\n :email xkubik34@stud.fit.vutbr.cz\nfrom\n Classes of custom transformations that are applied during the training as additional augmentation of the depth maps.\n\"\"\"\n\nimport torch\nimport random\nimport numpy as np\nimport torch.nn.functional as F\n\nfrom random import randrange\nfrom skimage.transform import resize, warp, AffineTransform\n\n\nclass Normalize(object):\n \"\"\"Normalization of a depth map in the value of [0, 1] for each pixel.\"\"\"\n def __init__(self, input_type):\n self.input_type = input_type\n\n def __call__(self, sample):\n\n if self.input_type == 'geom':\n image, landmarks, label = sample['image'], sample['landmarks'], sample['label']\n\n mean, std = image.mean([1, 2]), image.std([1, 2])\n\n # TODO?\n\n return {'image': image,\n 'landmarks': landmarks,\n 'label': label}\n\n\nclass ToTensor(object):\n \"\"\"Transformation of a training sample into a torch tensor instance.\"\"\"\n def __init__(self, input_type):\n self.input_type = input_type\n\n def __call__(self, sample):\n image, landmarks, label = sample['image'], sample['landmarks'], sample['label']\n\n image = torch.from_numpy(image.copy())\n\n if self.input_type != 'depth+geom':\n image = image.unsqueeze(1)\n image = image.permute(1, 0, 2)\n else:\n image = image.permute(2, 0, 1)\n\n landmarks = np.asarray(landmarks)\n landmarks = torch.from_numpy(landmarks.copy())\n\n return {'image': image,\n 'landmarks': landmarks,\n 'label': label}\n\n\nclass Resize(object):\n \"\"\"Resizing of the input sample into provided dimensions.\"\"\"\n\n def __init__(self, width, height, input_type='image'):\n assert isinstance(width, int)\n assert isinstance(height, int)\n\n self.width = width\n self.height = height\n self.type = input_type\n\n def __call__(self, sample):\n image, landmarks, label = sample['image'], sample['landmarks'], sample['label']\n resized_landmarks = landmarks.copy()\n\n if self.type == 'image':\n image = resize(image, (self.height, self.width), anti_aliasing=True)\n if self.type == 'landmarks':\n resized_landmarks = []\n for landmark in landmarks:\n landmark_resized = resize(landmark, (self.height, self.width), anti_aliasing=True)\n resized_landmarks.append(landmark_resized)\n\n return {'image': image,\n 'landmarks': resized_landmarks,\n 'label': label}\n\n\nclass RandomTranslating(object):\n \"\"\"Randomly translate the input sample from range [-10 px, 10 px] with provided probability.\"\"\"\n\n def __init__(self, p=0.5):\n assert isinstance(p, float)\n\n self.p = p\n\n def __call__(self, sample):\n image, landmarks, label = sample['image'], sample['landmarks'], sample['label']\n translated_landmarks = landmarks.copy()\n\n if np.random.rand(1) < self.p:\n n1 = randrange(-10, 10)\n n2 = randrange(-10, 10)\n\n t = AffineTransform(translation=(n1, n2))\n\n image = warp(image, t.inverse)\n\n translated_landmarks = []\n for landmark in landmarks:\n translated_landmarks.append(warp(landmark, t.inverse))\n\n return {'image': image,\n 'landmarks': translated_landmarks,\n 'label': label}\n\n\nclass RandomScaling(object):\n \"\"\"Randomly scales the input sample with scale index from range [0.90, 1.10] with provided probability.\"\"\"\n\n def __init__(self, p=0.5):\n assert isinstance(p, float)\n\n self.p = p\n\n def __call__(self, sample):\n image, landmarks, label = sample['image'], sample['landmarks'], sample['label']\n scaled_landmarks = landmarks.copy()\n\n if np.random.rand(1) < self.p:\n n = random.uniform(0.90, 1.10)\n t = AffineTransform(scale=(n, n))\n\n image = warp(image, t.inverse)\n\n scaled_landmarks = []\n for landmark in landmarks:\n scaled_landmarks.append(warp(landmark, t.inverse))\n\n return {'image': image,\n 'landmarks': scaled_landmarks,\n 'label': label}\n\n\nclass RandomRotation(object):\n \"\"\"Randomly rotates the input sample from range [−11.25 deg, 11.25 deg] with provided probability.\"\"\"\n\n def __init__(self, p=0.5):\n assert isinstance(p, float)\n\n self.p = p\n\n def __call__(self, sample):\n image, landmarks, label = sample['image'], sample['landmarks'], sample['label']\n\n rnd_num1 = randrange(-32, -6)\n rnd_num2 = randrange(6, 32)\n rnd_num = random.choice([rnd_num1, rnd_num2])\n\n if np.random.rand(1) < self.p:\n rotated_image = self.rotate(x=image.unsqueeze(0).type(torch.FloatTensor), theta=np.pi/rnd_num)\n\n rotated_landmarks = []\n for _, landmark in enumerate(landmarks):\n rotated_landmark = self.rotate(x=landmark.unsqueeze(0).unsqueeze(0).type(torch.FloatTensor), theta=np.pi/rnd_num)\n rotated_landmarks.append(rotated_landmark.squeeze(0))\n\n result = torch.cat(rotated_landmarks, dim=0)\n\n return {'image': rotated_image.squeeze(0),\n 'landmarks': result,\n 'label': label}\n\n return {'image': image,\n 'landmarks': landmarks,\n 'label': label}\n\n @staticmethod\n def get_rotation_matrix(theta):\n \"\"\"Returns a tensor rotation matrix with given theta value.\"\"\"\n\n theta = torch.tensor(theta)\n\n return torch.tensor([[torch.cos(theta), -torch.sin(theta), 0],\n [torch.sin(theta), torch.cos(theta), 0]])\n\n def rotate(self, x, theta):\n rot_mat = self.get_rotation_matrix(theta)[None, ...].repeat(x.shape[0], 1, 1)\n grid = F.affine_grid(rot_mat, x.size(), align_corners=False)\n x = F.grid_sample(x, grid, align_corners=False)\n\n return x\n"},"avg_line_length":{"kind":"number","value":31.6787564767,"string":"31.678756"},"max_line_length":{"kind":"number","value":129,"string":"129"},"alphanum_fraction":{"kind":"number","value":0.5966633955,"string":"0.596663"},"score":{"kind":"number","value":3.21875,"string":"3.21875"}}},{"rowIdx":915,"cells":{"hexsha":{"kind":"string","value":"b2c14d3bb32a9d0a97a9d773d034e8784a7e69a4"},"size":{"kind":"number","value":5641,"string":"5,641"},"ext":{"kind":"string","value":"py"},"lang":{"kind":"string","value":"Python"},"max_stars_repo_path":{"kind":"string","value":"lljs.py"},"max_stars_repo_name":{"kind":"string","value":"Peter9192/wind_analytics"},"max_stars_repo_head_hexsha":{"kind":"string","value":"604136be1c2ef1155bdb7579c7d123525dbe10d8"},"max_stars_repo_licenses":{"kind":"list like","value":["Apache-2.0"],"string":"[\n \"Apache-2.0\"\n]"},"max_stars_count":{"kind":"null"},"max_stars_repo_stars_event_min_datetime":{"kind":"null"},"max_stars_repo_stars_event_max_datetime":{"kind":"null"},"max_issues_repo_path":{"kind":"string","value":"lljs.py"},"max_issues_repo_name":{"kind":"string","value":"Peter9192/wind_analytics"},"max_issues_repo_head_hexsha":{"kind":"string","value":"604136be1c2ef1155bdb7579c7d123525dbe10d8"},"max_issues_repo_licenses":{"kind":"list like","value":["Apache-2.0"],"string":"[\n \"Apache-2.0\"\n]"},"max_issues_count":{"kind":"null"},"max_issues_repo_issues_event_min_datetime":{"kind":"null"},"max_issues_repo_issues_event_max_datetime":{"kind":"null"},"max_forks_repo_path":{"kind":"string","value":"lljs.py"},"max_forks_repo_name":{"kind":"string","value":"Peter9192/wind_analytics"},"max_forks_repo_head_hexsha":{"kind":"string","value":"604136be1c2ef1155bdb7579c7d123525dbe10d8"},"max_forks_repo_licenses":{"kind":"list like","value":["Apache-2.0"],"string":"[\n \"Apache-2.0\"\n]"},"max_forks_count":{"kind":"null"},"max_forks_repo_forks_event_min_datetime":{"kind":"null"},"max_forks_repo_forks_event_max_datetime":{"kind":"null"},"content":{"kind":"string","value":"\"\"\" Identify low-level jets in wind profile data.\n\nPeter Kalverla\nDecember 2020\n\"\"\"\n\nimport numpy as np\nimport xarray as xr\n\n\ndef detect_llj(x, axis=None, falloff=0, output='strength', inverse=False):\n \"\"\" Identify maxima in wind profiles.\n\n args:\n - x : ndarray with wind profile data\n - axis : specifies the vertical dimension\n is internally used with np.apply_along_axis\n - falloff : threshold for labeling as low-level jet\n default 0; can be masked later, e.g. llj[falloff>2.0]\n - output : specifiy return type: 'strength' or 'index'\n\n returns (depending on