Skip to content

Instantly share code, notes, and snippets.

View atomize's full-sized avatar
🎹
♩♩

Berti atomize

🎹
♩♩
View GitHub Profile
package main
import (
"bufio"
"flag"
"fmt"
"io"
"os"
"path/filepath"
"regexp"
@atomize
atomize / onchange.sh
Created October 18, 2018 22:25 — forked from senko/onchange.sh
Watch current directory and execute a command if anything in it changes
#!/bin/bash
#
# Watch current directory (recursively) for file changes, and execute
# a command when a file or directory is created, modified or deleted.
#
# Written by: Senko Rasic <[email protected]>
#
# Requires Linux, bash and inotifywait (from inotify-tools package).
#
# To avoid executing the command multiple times when a sequence of
@atomize
atomize / s3.sh
Created October 18, 2018 19:58 — forked from chrismdp/s3.sh
Uploading to S3 in 18 lines of Shell (used to upload builds for http://soltrader.net)
# You don't need Fog in Ruby or some other library to upload to S3 -- shell works perfectly fine
# This is how I upload my new Sol Trader builds (http://soltrader.net)
# Based on a modified script from here: http://tmont.com/blargh/2014/1/uploading-to-s3-in-bash
S3KEY="my aws key"
S3SECRET="my aws secret" # pass these in
function putS3
{
path=$1
@atomize
atomize / promise_map.js
Created August 17, 2018 21:30 — forked from tokland/promise_map.js
Execute an array of promises sequentially and collect the result
function promiseMap(xs, f) {
const reducer = (ysAcc$, x) =>
ysAcc$.then(ysAcc => f(x).then(y => ysAcc.push(y) && ysAcc));
return xs.reduce(reducer, Promise.resolve([]));
}
/* Example */
const axios = require('axios');
@atomize
atomize / index.js
Created July 7, 2018 01:24 — forked from yandzee/index.js
Code retry with promises
// Author: Renat Tuktarov ([email protected])
const retry = function(fn, prev) {
return new Promise((current, reject) => {
const resolve = _ => (prev && prev()) || current();
fn(resolve, delay => {
setTimeout(_ => {
retry(fn, resolve);
}, delay);
@atomize
atomize / mapOrderES6.js
Last active May 21, 2018 22:20 — forked from ecarter/mapOrder.js
Order an array of objects based on another array order ES6
/*
Sort array of objects based on another array
Original function:
function mapOrder (array, order, key) {
array.sort( function (a, b) {
var A = a[key], B = b[key];
if (order.indexOf(A) > order.indexOf(B)) {
return 1;
} else {
@atomize
atomize / README.MD
Created May 9, 2018 20:04 — forked from KaraAJC/README.MD
ReadMe Template

Title

Description

Add a one-sentence description of this project. and a link to the live demo.

Features

  • completed feature: What this feature does
  • pending feature: What this feature does

ScreenShots

@atomize
atomize / rate_limit.js
Created May 4, 2018 00:11 — forked from mattheworiordan/rate_limit.js
Rate limiting function calls with JavaScript and Underscore.js
/* Extend the Underscore object with the following methods */
// Rate limit ensures a function is never called more than every [rate]ms
// Unlike underscore's _.throttle function, function calls are queued so that
// requests are never lost and simply deferred until some other time
//
// Parameters
// * func - function to rate limit
// * rate - minimum time to wait between function calls
// * async - if async is true, we won't wait (rate) for the function to complete before queueing the next request
@atomize
atomize / websockets-server.js
Created March 27, 2018 16:47 — forked from bradwright/websockets-server.js
Pure Node.js WebSockets server
/*
* node-ws - pure Javascript WebSockets server
* Copyright Bradley Wright <[email protected]>
*/
// Use strict compilation rules - we're not animals
'use strict';
var net = require('net'),
crypto = require('crypto');
@atomize
atomize / tmux.md
Created November 17, 2017 00:16 — forked from avelino/tmux.md
tmux cheat sheet

tmux - terminal multiplexer

Managing tmux sessions:

$ tmux      # start tmux server
$ tmux at   # attach running sessions to a terminal
$ tmux ls   # list running tmux sessions

Sharing sessions between terminals:

$ tmux new -s session_name # make new named session

$ tmux at -t session_name # attach to exist session (allowing shared sessions)