Skip to content

Instantly share code, notes, and snippets.

View nadeesha's full-sized avatar

Nadeesha Cabral nadeesha

View GitHub Profile
@nadeesha
nadeesha / Markdium-JSX.jsx
Created October 22, 2021 20:22
Markdium-Using a .netrc to securely store remote server credentials
$cat ~/.netrc
machine api.usecloudstate.io
login me@example.com
password c4cd94da15ea0544802c2cfd5ec4ead324327111
machine github.com
login me@example.com
password c2224da15ea0544802c2cfd5ec4ead324327430
const successNoContent = [
(data: string) => data.length === 0,
() => 204,
];
const successWithContent = [
(data: string) => data.length > 0,
() => 200
];
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")
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;
}
});
export function tryCatch<Props, Result>({
tryer,
catcher
}: {
tryer: (props: Props) => Result;
catcher: (props: Props, message: string) => Result;
}) {
return (props: Props) => {
try {
return tryer(props);
export function tryCatch({
tryer,
catcher
}) {
return (props) => {
try {
return tryer(props);
} catch (e) {
return catcher(props, e.message);
}
function setUserLanguageCode(selectedLanguage) {
const languageCode = getLanguageCode(selectedLanguage);
let storedSuccessfully;
try {
window.localStorage.setItem("LANG_CODE", languageCode);
storedSuccessfully = true;
} catch (e) {
storedSuccessfully = false;
export const conditionally = <Props, Result>(options: {
if: (props: Props) => any;
then: (props: Props) => Result | Result;
else: (props: Props) => Result | Result;
}) => (props: Props) => {
return options.if(props) ? options.then(props) : options.else(props);
};
export const conditionally = (config) => (props) => {
return config.if(props) ?
config.then(props) : config.else(props);
};
const hasGoodRating = rating => rating > 4;
const priceChange = conditionally({
if: hasGoodRating,
then: rating => 1000 * rating,
else: () => 1000,
});
const getDescription = conditionally({
if: hasGoodRating,