Skip to content

Instantly share code, notes, and snippets.

View tobiashm's full-sized avatar

Tobias H. Michaelsen tobiashm

View GitHub Profile
@tobiashm
tobiashm / version-check.sh
Created October 6, 2015 07:04
Version check in Bash
awk -v ver="$(npm -v)" 'BEGIN { if (ver > 2.0) exit 1; }' && npm i -g npm@2
@tobiashm
tobiashm / linter-rubocop
Last active July 8, 2016 09:58
Run Rubocop from Atom with the RVM
#!/bin/bash
function upsearch () {
test / == "$PWD" && return || test -e "$1" && cat "$PWD/$1" && return || cd .. && upsearch "$1"
}
ruby_version=$(upsearch ".ruby-version")
$HOME/.rvm/bin/rvm ${ruby_version:-default} do bundle exec rubocop $@
@tobiashm
tobiashm / generic_type.rb
Created June 26, 2015 11:59
Dynamic type creation for inheritance
class Task
def model
fail "Must be implemented in sub-class"
end
# ...
end
def Task(model)
Class.new(Task) { cattr_reader :model; @model = model }
end
// http://lea.verou.me/2012/04/background-attachment-local/
@mixin scroll-shadow($color: #fff, $width: 100%, $offset: 0) {
background-image: /* Legacy - prefixed */
/* Shadow covers */
-webkit-linear-gradient($color 30%, rgba($color, 0)),
-webkit-linear-gradient(rgba($color, 0), $color 70%),
/* Shadows */
-webkit-radial-gradient(50% 0, farthest-side, rgba(0, 0, 0, .2), rgba(0, 0, 0, 0)),
-webkit-radial-gradient(50% 100%, farthest-side, rgba(0, 0, 0, .2), rgba(0, 0, 0, 0));
background-image: /* Legacy */
@tobiashm
tobiashm / callback_as_promise.js
Created May 6, 2015 14:38
Convert Node callback to Promise
function callbackAsPromise(fn, scope) {
return function() {
var args = Array.prototype.slice.apply(arguments);
return new Promise(function(resolve, reject) {
fn.apply(scope, args.concat(function(err, data) {
if (err) reject(err);
resolve(data);
}));
});
}
@tobiashm
tobiashm / pathname-slash.rb
Created April 28, 2015 19:54
Join Ruby Pathname with slashes
require "pathname"
Pathname.class_eval { alias join / }
Pathname.new("foo") / "bar" / "baz" # => #<Pathname:foo/bar/baz>
@tobiashm
tobiashm / misc.md
Last active August 29, 2015 14:16
“Inspirational quotes”

Q: How does an app become bloated?

A: One reasonable feature request at a time

via


@tobiashm
tobiashm / blueprint_mock_server.rb
Created February 21, 2015 12:37
Create a simple mock server from API Blueprint document for testing
require "addressable/template"
require "redsnow"
require "sinatra"
class BlueprintMockServer
def initialize(base_url, blueprint)
@mocks = {}
api = RedSnow.parse(File.read(blueprint.to_s))
api.ast.resource_groups.flat_map(&:resources).each do |resource|
uri_template = Addressable::Template.new(base_url + resource.uri_template)
@tobiashm
tobiashm / capistrano-database.rb
Last active August 29, 2015 14:14
Capistrano recipe for creating PostgreSQL database user
Capistrano::Configuration.instance(true).load do
namespace :db do
desc "Create database user for current site"
task :create_user, roles: :db do
config = Pathname.new(__dir__).join("..", "database.yml")
config = ERB.new(config.read).result(binding)
config = YAML.load(config)
fail "No database config for #{stage}" unless config[stage.to_s]
username, password = config[stage.to_s].values_at("username", "password")
run "#{sudo as: 'postgres'} psql -d postgres" do |channel, _, _|
@tobiashm
tobiashm / a.md
Last active August 29, 2015 14:14 — forked from rkh/a.md

This allows you to use the following video streaming services outside of the US from your Mac without having to use a proxy or VPN, so no big bandwidth issues:

  • Hulu / HuluPlus
  • CBS
  • ABC
  • MTV
  • theWB
  • CW TV
  • Crackle
  • NBC