Skip to content

Instantly share code, notes, and snippets.

@dhh
dhh / Gemfile
Created Jun 24, 2020
HEY's Gemfile
View Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@jamis
jamis / maze.hs
Last active Aug 29, 2015
An implementation of the Recursive Backtracker maze generation algorithm in Haskell
View maze.hs
{- --------------------------------------------------------------------------
- A naive random maze generator.
-
- $ ghc -o maze Maze.hs
- $ maze 10 10
-
- Author: Jamis Buck (jamis@jamisbuck.org)
- ------------------------------------------------------------------------ -}
module Main where
@jamis
jamis / maze.erl
Created Aug 17, 2015
An implementation of the Recursive Backtracker maze generation algorithm in Erlang
View maze.erl
-module(maze).
-export([generate/2,north/3,south/3,west/3,east/3,visualize/1]).
% Generate and return a maze of width W and height H.
generate(W,H) -> try_directions(random:uniform(W)-1, random:uniform(H)-1, directions(), {width,W,height,H,0}).
% Returns true if there is a passage north from the given position in the maze.
north(X,Y,Maze) -> at(X,Y,Maze) band 2#1 =/= 0.
% Returns true if there is a passage south from the given position in the maze.
@AndrewRadev
AndrewRadev / eruby.vim
Created Jul 1, 2012
My ftplugin/eruby.vim file
View eruby.vim
" This file is supposed to be saved as "~/.vim/ftplugin/eruby.vim". If desired, parts of it can be
" picked and saved into separate files in the same directory as long as they start with "eruby_",
" for example "~/.vim/ftplugin/eruby_surroundings.vim".
" Surround mappings. The character defines the mapping. Most of these are meant for use in visual
" mode to add a wrapping, although they can probably be used otherwise as well.
"
" These ones let you wrap a piece of text on a line with erb <% %> markers. The last one is
" particularly useful for adding translations in the place of hardcoded strings.
"
@jeremyf
jeremyf / fast-one.rb
Created May 10, 2012
A command line tool to help with testing pull requests.
View fast-one.rb
#!/usr/bin/env ruby
# Before you use this:
# git clone git://github.com/some-other-user/their-repo
# This assumes that origin is the repo that you are merging into!
require 'rubygems'
gem 'rest-client'
gem 'crack'
require 'rest-client'
View apology101.markdown

Chances are your head's spinning right now. That accusation of bias caught you off guard, you got kind of defensive, and now all hell has broken loose. You're feeling attacked on all sides. You're a good person at heart, and having all these people treat you like the antichrist is pretty upsetting.

You need to say something, but you're probably not in the best headspace to write copy right now. So to help you along, here's my 100% guaranteed-or-you-money-back scandal defusement apology template:

@basgys
basgys / gist:1482038
Created Dec 15, 2011
Trigger call to all passenger instances
View gist:1482038
#!/bin/bash
if [ -z $1 ]; then
echo "Usage : "$0" http://passenger_address"
else
echo "address to call: "$1
passenger-status --verbose | grep 'Password:' | cut -d ':' -f2 | while read line; do
echo "Calling : "$line # Passenger instance password
curl --header "X-Passenger-Connect-Password: "$line $1 > /dev/null 2>&1
@bsodmike
bsodmike / application.rb
Last active Sep 27, 2015
Modified config/application.rb to print out initialization points for Rails 3.2.11
View application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
@dhh
dhh / gist:1014971
Created Jun 8, 2011
Use concerns to keep your models manageable
View gist:1014971
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@madrobby
madrobby / README.md
Created May 17, 2011 — forked from 140bytes/LICENSE.txt
Luhn10 algorithm
View README.md

Implementation of the Luhn 10 algorithm to check validity of credit card numbers. See http://en.wikipedia.org/wiki/Luhn_algorithm for details on the algorithm.

var validCreditCard = function(a,b,c,d,e){for(d=+a[b=a.length-1],e=0;b--;)c=+a[b],d+=++e%2?2*c%10+(c>4):c;return!(d%10)};

validCreditCard('378282246310005'); //=> true
validCreditCard('378282246310006'); //=> false

// some numbers to test with
// 378282246310005 371449635398431 378734493671000