Skip to content

Instantly share code, notes, and snippets.

View wffranco's full-sized avatar

Willem Franco wffranco

View GitHub Profile
@wffranco
wffranco / init.coffee
Last active February 14, 2017 14:20
AtomSettings
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@wffranco
wffranco / fetch.js
Last active January 5, 2023 15:35
node.js fetch get
const fetch = url => new Promise((resolve, reject) => {
https.get(url, res => {
res.setEncoding('utf8');
let result = null;
res.on('data', data => {
result = JSON.parse(data);
});
res.on('end', () => {
if (res.statusCode != 200) {
reject("Error code " + res.statusCode);
@wffranco
wffranco / case-replacement.js
Last active August 1, 2022 16:49
Case Replacement
/** dash between num-letter */ const dbnl = [/(\d)([a-zA-Z])|([a-zA-Z])(\d)/g, '$1$3-$2$4'];
/** special characters to dash */ const sc2d = [/[^a-zA-Z0-9]+/g, '-'];
/** uppercase to dash */ const u2d = [/([A-Z])/g, '-$1'];
/** Common preconversion */
const commonPre = fn => cacheStringFunction(str => fn(str.replace(...u2d).replace(...dbnl).replace(...sc2d)));
/** dash before a letter */ const dbl = /-([a-zA-Z])/g;
export const capitalizeWords = cacheStringFunction(str => str.toLowerCase().replace(/\b(\w)/g, (_, c) => (c ? c.toUpperCase() : '')));
@wffranco
wffranco / node-check.js
Created January 14, 2023 17:26
Node check (install/update packages if required)
/* eslint-disable @typescript-eslint/no-var-requires */
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const paths = [
path.resolve(__dirname, 'package.json'),
path.resolve(__dirname, 'node_modules', 'last.package.json'),
];
@wffranco
wffranco / sail
Created May 22, 2023 00:45
Sail local command for laravel with php 8.1. Add `sail init`, allowing the first download of `vendor` folder (without it you can't run sail)
#!/usr/bin/env bash
cd "$(dirname "${BASH_SOURCE[0]}")"
#if the command is called with `init` param, or `vendor` folder is missing
if [ "$1" = "init" ] || [ ! -d vendor ]; then
#run laravel sail container to run `composer install`
docker run --rm \
-u "$(id -u):$(id -g)" \
-v $(pwd):/var/www/html \