Skip to content

Instantly share code, notes, and snippets.

View itelo's full-sized avatar
🎯
Focusing

itelo itelo

🎯
Focusing
View GitHub Profile
type ListZipper<T> = [T[], T[]];
function toListZipper<T>(list: T[]): ListZipper<T>;
function toListZipper<T>(list: T[]) {
return [[], list];
}
function fromListZipper<T>(lz: ListZipper<T>): T[]
function fromListZipper<T>([L, R]: ListZipper<T>) {
return [...L.reverse(), ...R];
@itelo
itelo / listzip.clj
Last active December 18, 2019 00:27
(ns listzip.core)
(defn toListZipper
"I don't do a whole lot."
[lToLz]
(list (list) lToLz))
(defn fromListZipper
[lz]
(let [left (first lz)
@itelo
itelo / init.0ebbc73b06d4244d4f1a640e6018b349f29e33ec.ts
Created February 2, 2020 21:56
medium:create-react-app-from-zero:init-"base command created with success"
import { GluegunToolbox, print } from 'gluegun'
module.exports = {
name: 'init',
alias: ['init'],
run: async (toolbox: GluegunToolbox) => {
print.success('base command created with success');
},
}
type ExtractPromiseGeneric<P> = P extends Promise<infer T> ? T : never;
const currentDirectory = fs.realpathSync(process.cwd());
function throwError(func: Function) {
return func;
}
function CatchError(err: Function | Error) {
if (typeof err === 'function') {
module.exports = {
name: 'init',
alias: ['init'],
run: async (toolbox: GluegunToolbox) => {
/**
* initing global/local variables
*/
const projectName = toolbox.parameters.options.name;
const templateName = toolbox.parameters.options.template;
import * as fse from 'fs-extra';
function checkIfNameExistsInDirectory(appDirectory) {
return async () => {
if (!(await fse.pathExists(appDirectory))) {
return
}
throw throwError(() => {
print.error('Invalid project name')
function getNpmTemplatePackageName(templateName: string) {
return async () => {
if (templateName) {
return `cra-clone-${templateName}-template`;
}
return 'cra-clone-template';
}
}
import { execSync } from 'child_process'
async function getNpmPackageUrl(
npmTemplatePackageName: ExtractPromiseGeneric<
ReturnType<ReturnType<typeof getNpmTemplatePackageName>>
>
) {
return {
npmTemplatePackageName,
urlNpmPackage: execSync(`npm v ${npmTemplatePackageName} dist.tarball`)
import * as hyperquest from 'hyperquest'
import { unpack } from 'tar-pack'
function extractStream(stream, dest) {
return new Promise((resolve, reject) => {
stream.pipe(
unpack(dest, err => {
if (err) {
reject(err)
} else {
function copyTemplateToAppDirectory(tmpDir: string, appDirectory: string) {
return async (
chainData: ExtractPromiseGeneric<ReturnType<typeof getNpmPackageUrl>>
) => {
print.info(`copying template to ${appDirectory}`);
await fse.copy(`${tmpDir}/template`, appDirectory, {
overwrite: false,
errorOnExist: true
});