Skip to content

Instantly share code, notes, and snippets.

View pateketrueke's full-sized avatar

Alvaro Cabrera Durán pateketrueke

View GitHub Profile
@pateketrueke
pateketrueke / Hakifile.js
Last active December 4, 2018 03:58
Hakifile.js example
module.exports = haki => {
haki.setGenerator('the:truth', {
description: "Display if it's true, or not",
arguments: ['verb', 'value'],
abortOnFail: true,
actions(input) {
const { verb, value } = input;
if (verb === 'is' && parseInt(value, 10) === 42) {
console.log('Gotcha!');
<?php
$start = memory_get_usage(true);
define('INPUT_FILE', $argv[1]);
define('IS_DECODE', array_search('--decode', $argv) !== false);
if (!is_file(INPUT_FILE)) {
echo "Invalid or missing input.\n";
echo "Usage: php extract-xml.php download.xml [--decode]\n";
@pateketrueke
pateketrueke / env.sh
Created May 18, 2018 20:52
Extract ENV vars from JSON files
#!/bin/bash
set -eu
echo "$( tr '\n' ' ' < vars.json | jq -r 'keys[] as $k | "export \($k)=\"\(.[$k])\""' )"
# usage:
# ./env.sh > .env
#. source .env
# echo "$SOME_ENV_VALUE"
@pateketrueke
pateketrueke / lvm_apt_get.txt
Created May 9, 2018 22:04
Mount and install through LVM
vgchange -a y
mkdir /newroot
mount /dev/yourVG/rootLV /newroot
mount /dev/yourbootpartition /newroot/boot
mount -o bind /dev /newroot/dev
mount -o bind /sys /newroot/sys
mount -o bind /var /newroot/var
mount -o bind /proc /newroot/proc
@pateketrueke
pateketrueke / dl.md
Created February 2, 2018 17:52
Una lista de definiciones, el drama.

Problema

Dada la lista de definiciones de abajo:

<dl>
  <dt>x</dt>
  <dd>a</dd>
  <dd>b</dd>
@pateketrueke
pateketrueke / sinon-stubs-fix.md
Created January 17, 2018 00:15
Patch sinon-stubs for v2

Given sources with similar content:

anySymbolHere.stub(anObject, stringRef, hoistedFn);
anySymbolHere.stub(anObject, 'anyMethodCallAsString', () => true);

Execute the following command in your terminal:

sed -i '' 's/.stub(\(.*\), \(.*\));/.stub(\1).callsFake(\2);/g' *.js

@pateketrueke
pateketrueke / application.css
Last active April 4, 2018 03:36
JSON Schema Resource
hr,iframe{border:0}.is-loading,select{background-repeat:no-repeat}.button-group a,.field-item>a,a{text-decoration:none}.info-table,.json-table,table{border-collapse:collapse}html{box-sizing:border-box}*,:after,:before{box-sizing:inherit}body,html{height:100%}blockquote,body,dd,dl,dt,fieldset,figure,h1,h2,h3,h4,h5,h6,hr,html,iframe,legend,li,ol,p,pre,textarea,ul{margin:0;padding:0}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:400}ul{list-style:none}button,input,select,textarea{margin:0}.json-form,hr{margin-bottom:12px}audio,embed,iframe,img,object,video{height:auto;max-width:100%}table{border-spacing:0}td,th{padding:0;text-align:left}a,body,button,input{font-family:Helvetica;color:#000}svg{max-width:1em;max-height:1em}svg.big{max-width:1.5em;max-height:1.5em}svg.small{max-width:.75em;max-height:.75em}small{color:#aaa;font-size:.8em}a{color:#999}a:hover{color:#000}a:hover svg{fill:#000}.has-icon>a svg,.has-icon>span svg,a svg{fill:#999}a svg{vertical-align:middle}hr{border-top:1px dashed #aaa;margin-top:12px}but
@pateketrueke
pateketrueke / grown.js
Last active November 9, 2017 10:27
Grown v1 DSL
'use strict';
const IS_LIVE = process.argv.slice(2).indexOf('--live') > -1;
require('debug').enable('*');
const Grown = require('./_plugs/grown');
Grown.use(require('./_plugs/router'));
Grown.use(require('./_plugs/test'));
@pateketrueke
pateketrueke / vue-template-compiler-bug.js
Created April 2, 2017 08:02
Ctor.toString() breaks on environments where Reflect.ownKeys is undefined (e.g. node v4.8.1)
// this "can" simulate the real issue behind
global.Reflect = global.Reflect || {};
global.Reflect.ownKeys = null;
// this will call `Ctor.toString()` at some point,
// and there will be dragons (fix with String(Ctor) huh?)
require('vue-template-compiler');
#!/bin/bash
SRC="$HOME/sites"
DEST="/etc/caddy"
setup() {
SITE_CONF="$(cat $SRC/$1/Caddyfile)"
SITE_HOST="$(cat $SRC/$1/HOSTS)"
SITE_CONF="$(echo "$SITE_CONF" | sed "s/localhost/$SITE_HOST/g" )"