Skip to content

Instantly share code, notes, and snippets.

View atomize's full-sized avatar
🎹
♩♩

Berti atomize

🎹
♩♩
View GitHub Profile
@atomize
atomize / shellworkflow.vim
Created November 15, 2017 17:07
.vimrc function to run script in VIM and display output in split window
function! s:ExecuteInShell(command)
let command = join(map(split(a:command), 'expand(v:val)'))
let winnr = bufwinnr('^' . command . '$')
silent! execute ':w'
silent! execute winnr < 0 ? 'vnew ' . fnameescape(command) : winnr . 'wincmd w'
setlocal buftype=nowrite bufhidden=wipe nobuflisted noswapfile nowrap number
silent! execute 'silent %!'. command
silent! redraw
silent! execute 'au BufUnload <buffer> execute bufwinnr(' . bufnr('#') . ') . ''wincmd w'''
silent! execute 'nnoremap <silent> <buffer> <LocalLeader>r :call <SID>ExecuteInShell(''' . command . ''')<CR>'
@atomize
atomize / i3-cheat-sheet.md
Created November 17, 2017 00:15 — forked from JeffPaine/i3-cheat-sheet.md
i3 Window Manager Cheat Sheet

i3 Window Manager Cheat Sheet

$mod refers to the modifier key (alt by default)

General

  • startx i3 start i3 from command line
  • $mod+<Enter> open a terminal
  • $mod+d open dmenu (text based program launcher)
  • $mod+r resize mode ( or to leave resize mode)
  • $mod+shift+e exit i3
@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)

@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 / 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 / devnull.txt
Created May 8, 2018 23:47
Advance I/O redirection in bash. /dev/null
For those unfamiliar with 'advanced' i/o redirection in bash:
1) 2>&- ("close output file descriptor 2", which is stderr) has the same result as 2> /dev/null;
2) >&2 is a shortcut for 1>&2, which you may recognize as "redirect stdout to stderr".
See the Advanced Bash Scripting Guide i/o redirection page for more info.
– mikewaters Dec 21 '11 at 19:48
-comment from : https://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script
@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 / 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 / RateLimit.js
Created July 6, 2018 16:13
Pure Javascript rate limit function. [https://jsfiddle.net/47cbj/56/]
function RateLimit(fn, delay, context) {
var queue = [], timer = null;
function processQueue() {
var item = queue.shift();
if (item)
fn.apply(item.context, item.arguments);
if (queue.length === 0)
clearInterval(timer), timer = null;
}
@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);