Skip to content

Instantly share code, notes, and snippets.

vaz /
Created Aug 11, 2019
script to make random junk files of specific sizes
set -e
function randomfile {
local numbytes="$1"
local outfile="$2"
{ cat /dev/urandom | # read random byte stream
base64 | # base64-encode the garbage so it's safely printable
fold -w 79 | # fold lines at 79 chars (80 char line w/ newline)
vaz / holidayobfuscation.js
Created Dec 22, 2017 — forked from krsnachandra/holidayobfuscation.js
Submission for LHL holiday obfuscation contest
View holidayobfuscation.js
function g() {
let a='Noel';
let b='Yuletide';
let c='Santa Claus';
let d='Rudolph';
let e='Snowflake';
let f='Occasion';
let g='North Pole';
let h='Christmas Tree';
let i='Joy';
vaz / js-callback-args.js
Created Oct 9, 2017
Ruby blocks vs JS callbacks
View js-callback-args.js
function benchmark(cb) {
const start_time = 12345;
const result = cb('some message');
console.log("the return value of cb was: ", result);
const end_time = 12456;
return end_time - start_time
vaz /
Last active Sep 29, 2017
knex migrations: associating records

Knex seeds: associating records

It's easiest if you're associating records between tables if you do it in one seed file. There are other ways but for now this is probably easiest.

PostgreSQL will generate your id fields for you, so don't put them in your seeds! Instead, take advantage of the returning chainable method from knex. See the below seed file and also docs.

vaz /
Last active Oct 31, 2020
Various fixes for file-watching and live-reloading when running servers in Vagrant

Vagrant fixes for file-watching servers

These snippets show how to enable polling for filesystem changes when using

  • nodemon for Node apps (ExpressJS, etc)
  • rails server
  • webpack-dev-server --watch
  • ember server

You can probably look at these examples and Google to find similar solutions for other dev servers.

vaz / 1.js
Last active Jun 6, 2017
request examples
View 1.js
var request = require('request');
var url = '';
// basic use
request.get(url, function(err, response, body) {
if (err) {
console.log("Error:", err);
} else {
// response.body == body
vaz / promise-example.js
Created May 31, 2017
Promise example - chaining and parallel execution
View promise-example.js
// Promises example
// just a helper, which returns a promise that resolves after
// 500-1000 milliseconds with whatever `args` were passed in
function fakeKnex(...args) {
return new Promise((resolve, reject) => {
function() { resolve(...args) },
500 + (Math.floor(Math.random() * 500)))
vaz / promises-are-fun.js
Created Apr 19, 2017
promises are fun.
View promises-are-fun.js
// this is coming from a library
function delayedValue(x) {
return new Promise((resolve, reject) => {
setTimeout(() => resolve(x), 1000)
// module doQuery.js
function doQuery() {
return delayedValue({
vaz / ar-or-statesman-error.rb
Created Nov 15, 2016
AR or Statesman, error handling patterns in controller (sort of pseudocode)
View ar-or-statesman-error.rb
# ActiveRecordish pattern
def create
@thing = Thing.create!(thing_params)
redirect_to @thing
rescue Thing::Invalid #???
# flash error
# re-render
View 1_use_strict.js
// If the first statement in a file or a function is "use strict"
// then Strict Mode will be activated for that file or function.
// You could invoke strict mode for the file by uncommenting this:
// "use strict";
function nonStrictFunction () {
x = 123; // undeclared!