This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private double FuzzyStringComparison(string source, string target) | |
{ | |
// if both of the strings are empty, return 0 | |
// else if the source is empty but not the target, the distance is the target length | |
// else if the target is empty and not the source, the the distance is the source length. | |
if (string.IsNullOrEmpty(source)) | |
{ | |
if (string.IsNullOrEmpty(target)) | |
{ | |
return 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$cat ~/.netrc | |
machine api.usecloudstate.io | |
login me@example.com | |
password c4cd94da15ea0544802c2cfd5ec4ead324327111 | |
machine github.com | |
login me@example.com | |
password c2224da15ea0544802c2cfd5ec4ead324327430 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from: http://www.typescriptlang.org/play/#src=function%20someFactory%3CT%3E()%20%7B%0D%0A%20%20return%20class%20%7B%0D%0A%20%20%20%20method(someParam%20%3A%20T)%20%7B%0D%0A%20%20%20%20%20%20%0D%0A%20%20%20%20%7D%0D%0A%20%20%7D%0D%0A%7D%0D%0A%0D%0A%2F%2F%20how%20to%20invoke%20this%20factory%20with%20a%20defined%20%3CT%3E%3F%0D%0A%0D%0Aconst%20SomeClass%20%3D%20someFactory%3C%7B%20whatever%3A%20string%20%7D%3E()%0D%0Aconst%20someInstance%20%3D%20new%20SomeClass()%0D%0AsomeInstance.method('will-error-here')%0D%0A | |
function someFactory<T>() { | |
return class { | |
method(someParam : T) { | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function tryCatch<Props, Result>({ | |
tryer, | |
catcher | |
}: { | |
tryer: (props: Props) => Result; | |
catcher: (props: Props, message: string) => Result; | |
}) { | |
return (props: Props) => { | |
try { | |
return tryer(props); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const successNoContent = [ | |
(data: string) => data.length === 0, | |
() => 204, | |
]; | |
const successWithContent = [ | |
(data: string) => data.length > 0, | |
() => 200 | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { encaseP, node, encase, map, chain } from "fluture"; | |
const readFileF = filePath => node(done => fs.readFile(filePath, "utf8", done)); | |
const fetchF = url => encaseP(url => fetch(url)); | |
const jsonParseF = encase(jsonString => JSON.parse(jsonString)); | |
const getPackageDownloads = (npmPackageName, onSuccess, onFailure) => { | |
readFileF("package.json") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const hasGoodRating = rating => rating > 4; | |
const priceChange = conditionally({ | |
if: hasGoodRating, | |
then: rating => 1000 * rating, | |
else: () => 1000, | |
}); | |
const getDescription = conditionally({ | |
if: hasGoodRating, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function tryCatch({ | |
tryer, | |
catcher | |
}) { | |
return (props) => { | |
try { | |
return tryer(props); | |
} catch (e) { | |
return catcher(props, e.message); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const storeLanguageCode = tryCatch({ | |
tryer: (languageCode) => { | |
window.localStorage.setItem("LANG_CODE", languageCode); | |
return true; | |
}, | |
catcher: (languageCode, errorMessage) => { | |
logger.log(`${errorMessage} <-- happened while storing ${languageCode}`); | |
return false; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setUserLanguageCode(selectedLanguage) { | |
const languageCode = getLanguageCode(selectedLanguage); | |
let storedSuccessfully; | |
try { | |
window.localStorage.setItem("LANG_CODE", languageCode); | |
storedSuccessfully = true; | |
} catch (e) { | |
storedSuccessfully = false; |
NewerOlder