Skip to content

Instantly share code, notes, and snippets.

View djanowski's full-sized avatar

Damian Janowski djanowski

View GitHub Profile
const Mongoose = require('mongoose');
Mongoose.Promise = Promise;
Mongoose.connect(`mongodb://localhost/test-${Date.now()}`);
const PersonSchema = new Mongoose.Schema({
name: {
first: { type: String },
last: { type: String }
}
#!/usr/bin/env bash
# `nvm use` the version specified in package.json.
source $(brew --prefix nvm)/nvm.sh
set -eo pipefail
die() {
echo "$@" >&2
@djanowski
djanowski / autotest
Last active February 1, 2016 20:17
ag -l + entr = autotest!
#!/usr/bin/env bash
# Monitors your tree and runs tests when anything changes.
#
# Run `make`, `npm test`, etc. automatically detected.
#
# $ autotest
#
# Run a specific command on changes:
#
@djanowski
djanowski / .000-README
Last active January 25, 2016 18:37
Babel bug with `this` inside async arrow function - npm i && npm test
babel-preset-stage-2 pulls in the newest version of babel-plugin-transform-async-to-generator,
however the async arrow function still has `this` = `undefined`.
If I manually install babel-plugin-transform-async-to-generator and add it to the list of plugins
in .babelrc, everything works as expected.
Steps to reproduce:
$ npm install && npm test
require "benchmark"
$baz = nil
class Foo
def self.foo
@foo || $baz
end
end
require "benchmark"
COUNT = 1_000_000
@status = 200
Benchmark.bm(20) do |x|
x.report("noop") do
COUNT.times { }
end
@djanowski
djanowski / gist:6826538
Created October 4, 2013 14:10
Print tree by level
Node = Struct.new(:value, :children)
tree = Node.new(
1,
[
Node.new(
2,
[Node.new(5, []), Node.new(6, [])]
),
@djanowski
djanowski / vim-install
Created August 27, 2013 02:44
vim-install(1) -- Vim plugin installer for the rest of us.
#!/bin/bash
usage() {
cat >&2 <<EOS
Usage: vim-install <Git URL>
EOS
exit 1
}
@djanowski
djanowski / autoload_killer.rb
Created August 16, 2013 21:04
AutoloadKiller middleware. Helps you debug race conditions due to misuse of Kernel#autoload.
# If some requests in your web application fail but subsequent requests don't,
# you may be a victim of Kernel#autoload.
#
# As you know, Kernel#autoload is not thread-safe. Moreover, missing constants
# trigger requiring other files, which can some times do more than just provide
# that missing constant. Yet many libraries still use it:
# https://github.com/search?l=ruby&q=autoload+language%3Aruby&type=Code
#
# So if you think you're having any of these issues, this middleware should be
# able to provide a hint as to which files are the ones you should be requiring
@djanowski
djanowski / composition.rb
Created August 16, 2013 15:14
Cuba composition and status codes
require File.expand_path("helper", File.dirname(__FILE__))
setup do
users = Cuba.new do
on get do
on "foo" do
res.write "foo"
end
on "bar" do