Skip to content

Instantly share code, notes, and snippets.

View ricardobeat's full-sized avatar

Ricardo Tomasi ricardobeat

View GitHub Profile
@ricardobeat
ricardobeat / task.js
Last active November 4, 2020 18:02
Taks sample
const { task, read, write } = require('taks')
const _postcss = require('postcss')
const _rollup = require('rollup')
const _uglify = require('uglify-es')
const postcss = task.plugin(async function (input, output, options) {
let opts = Object.assign({ from: undefined, plugins: [] }, options)
let src = await read(input)
let { css } = await _postcss(opts.plugins).process(src, opts)
return write(output, css)
@ricardobeat
ricardobeat / task.js
Last active November 4, 2020 10:27
minimal task runner
#!/usr/bin/env node
const _tasks = {}
function task (name, fn) {
_tasks[name] = fn
}
task.run = async function (name, wait) {
if (!name) return console.warn(`Usage: node task [name]`)
if (!_tasks[name]) return console.warn(`No task named ${name}`)
@ricardobeat
ricardobeat / semaphore.js
Created March 3, 2011 01:30
simple semaphore for parallel async execution, with error handling.
function queue(name){
queue.q[name]++ || (queue.q[name] = 1);
return function(err){
if (err && queue.e[name]) queue.e[name](err);
else if (err) throw err;
process.nextTick(function(){
queue.q[name]--;
queue.check(name);
});
}
@ricardobeat
ricardobeat / git-open
Created September 29, 2014 12:05
git-open - open all modified files
#!/bin/bash
#
# Open all changed files in Sublime Text
#
# Install:
# save this file to /usr/local/bin/git-open
# chmod +x /usr/local/bin/git-open
#
# It will now be available as 'git open'
#
@ricardobeat
ricardobeat / README.md
Last active April 14, 2020 18:19
git remaster

git-remaster updates both your current branch and master branch simultaneously, while preserving all commited, staged and unstaged changes.

Install

Add git-remaster to your path and make it executable:

curl https://gist.githubusercontent.com/ricardobeat/9600953/raw/git-remaster.sh > /usr/local/bin/git-remaster
chmod +x /usr/local/bin/git-remaster
Promise.prototype.spread = function (fn) {
this.then(function (values) {
fn.apply(this, values)
})
}
function when () {
var requirements = Array.prototype.slice.call(arguments, 0)
return Promise.all(requirements.map(function(name){
@ricardobeat
ricardobeat / blocks.js
Created October 22, 2014 23:40
blocks 2
;(function(global){
var library = {}
var instances = {}
function define (name, factory) {
if (library[name]) {
throw new Error('Module '+ name +' already registered.')
}
library[name] = factory
@ricardobeat
ricardobeat / index.html
Created September 10, 2018 09:21
Inline event attributes benchmark
<!doctype html>
<body></body>
<script>
const events = [
'click',
'input',
'change',
'mouseenter',
'mouseleave',
proc ue_init {} {
lappend d + { }
for {set i 0} {$i < 256} {incr i} {
set c [format %c $i]
set x %[format %02x $i]
if {![string match {[a-zA-Z0-9]} $c]} {
lappend e $c $x
lappend d $x $c
}
}
@ricardobeat
ricardobeat / search.sh
Created April 10, 2017 14:47
Git: digging for lost code - unlabeled stashes etc
git fsck --no-reflogs | awk '/dangling commit/ {print $3}'| while read hash; do
echo "$hash"
git show $hash | grep -H -C4 svg
done