Skip to content

Instantly share code, notes, and snippets.

@vaz
vaz / mkdata.sh
Created August 11, 2019 00:32
script to make random junk files of specific sizes
#!/bin/sh
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
vaz / holidayobfuscation.js
Created December 22, 2017 21:00 — forked from krsnachandra/holidayobfuscation.js
Submission for LHL holiday obfuscation contest
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
vaz / js-callback-args.js
Created October 9, 2017 21:33
Ruby blocks vs JS callbacks
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
vaz / 1_README.md
Last active September 29, 2017 01:23
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 http://knexjs.org docs.

@vaz
vaz / vagrant-fixes-for-watch-polling.md
Last active October 31, 2020 12:50
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
vaz / 1.js
Last active June 6, 2017 02:11
request examples
var request = require('request');
var url = 'http://www.google.com';
// basic use
request.get(url, function(err, response, body) {
if (err) {
console.log("Error:", err);
} else {
// response.body == body
@vaz
vaz / promise-example.js
Created May 31, 2017 05:45
Promise example - chaining and parallel execution
// 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) => {
setTimeout(
function() { resolve(...args) },
500 + (Math.floor(Math.random() * 500)))
@vaz
vaz / promises-are-fun.js
Created April 19, 2017 22:06
promises are fun.
// 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
vaz / ar-or-statesman-error.rb
Created November 15, 2016 19:59
AR or Statesman, error handling patterns in controller (sort of pseudocode)
# ActiveRecordish pattern
def create
@thing = Thing.create!(thing_params)
redirect_to @thing
rescue Thing::Invalid #???
# flash error
# re-render
end
// 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!
}