Skip to content

Instantly share code, notes, and snippets.

View duncanbeevers's full-sized avatar
🔊


Duncan Beevers duncanbeevers

🔊

View GitHub Profile
@kimamula
kimamula / sort.js
Created October 28, 2017 15:46
JavaScript asynchronous sort
/**
* return the mid value among x, y, and z
* @param x
* @param y
* @param z
* @param compare
* @returns {Promise.<*>}
*/
async function getPivot(x, y, z, compare) {
if (await compare(x, y) < 0) {
@sindresorhus
sindresorhus / np.sh
Last active December 11, 2022 21:26
shell function for publishing node modules with some goodies
# npm publish with goodies
# prerequisite: `npm install -g trash`
# `np` with an optional argument `patch`/`minor`/`major`/`<version>`
# defaults to `patch`
np() {
trash node_modules &>/dev/null;
git pull --rebase &&
npm install &&
npm test &&
npm version ${1:-patch} &&
@blatyo
blatyo / iteration.rake
Created February 27, 2013 12:50
Just creates a rake task that does the same as `db:migrate` for a different directory. Uses the same schema migrations table that migrations use. We don't migrate down for iterations.
namespace :iteration do
desc "Runs the tasks for the current iteration"
task :current => 'iteration:migrate'
desc 'Runs the unrun iteration tasks'
task :migrate => :environment do
mig = ActiveRecord::Migrator.new(:up, File.join(Rails.root, 'db', 'iterations'))
mig.migrate
end
@alexspeller
alexspeller / source_maps.rb
Created September 16, 2012 00:03
Coffeescript Source Maps in Rails
# config/initializers/source_maps.rb
if Rails.env.development?
require 'open3'
module CoffeeScript
class SourceMapError < StandardError; end;
class << self
def map_dir
@royratcliffe
royratcliffe / ubuntu12.04-ruby1.9.1.erb
Created April 20, 2012 12:26
Chef bootstrap for Ubuntu Precise Pangolin (12.04) using Ruby 1.9
bash -c '
<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%>
(
cat <<'EOP'
gem: --bindir=/usr/bin --no-ri --no-rdoc
EOP
) > /tmp/gemrc
awk NF /tmp/gemrc > /etc/gemrc
rm /tmp/gemrc
@duncanbeevers
duncanbeevers / sc-dl-min.js
Created March 22, 2012 12:16 — forked from pheuter/sc-dl.js
Bookmarklet that generates download link for a Soundcloud upload
(function(window){var i,$sound,$buttonGroup;var $sounds=$(".sound");var clientId=require("config").get("client_id");var oauthToken=require("lib/connect").getAuthToken();var conversionHelper=require("lib/helpers/conversion-helper");var $downloadButton,size;var params,downloadUrl,onSuccess;for(i=$sounds.length-1;i>=0;i--){$sound=$($sounds[i]);var soundcloudUrl="https://soundcloud.com"+($sound.find(".soundTitle__title").attr("href")||window.location.pathname);params={url:soundcloudUrl,client_id:clientId};onSuccess=function($sound){return function(data){var params={client_id:clientId};downloadUrl=require("lib/url").stringify({query:params},data.stream_url+".mp3");$buttonGroup=$($sound.find(".sound__soundActions .sc-button-group")[0]);size=$buttonGroup.find(".sc-button:first")[0].className.match(/sc-button-((?:small)|(?:medium))/)[1];$downloadButton=$('<a class="sc-button sc-button-download sc-button-icon sc-button-responsive">Download</a>').attr({title:"Download this sound ("+conversionHelper.bytesToMB(data.origi
@bestie
bestie / pre-commit
Created September 16, 2011 20:28
Rails Git pre-commit hook for ensuring schema.rb and migration changes commit atomically
#!/usr/bin/env ruby
# vim: set syntax=ruby
# Ensures that changes to the Rails schema.rb file may only be committed if a
# migration file is also committed at the same time.
def schema_modified?
%x[ git diff --cached |grep schema.rb ] == ''
end
@rsanheim
rsanheim / gist:1054078
Created June 29, 2011 15:23
Devise + Spork + Rails 3.1 RC4 hacks to keep User model from loading prefork
Spork.prefork do
require "rails/application"
# Prevent Devise from loading the User model super early with it's route hacks for Rails 3.1 rc4
# see also: https://github.com/timcharper/spork/wiki/Spork.trap_method-Jujutsu
Spork.trap_method(Rails::Application, :reload_routes!)
Spork.trap_method(Rails::Application::RoutesReloader, :reload!)
# rest of your prefork here...
end
@bytespider
bytespider / LICENSE.txt
Created May 24, 2011 10:08 — forked from 140bytes/LICENSE.txt
Base64 Encode
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Rob Griffiths http://bytespider.eu
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE