Skip to content

Instantly share code, notes, and snippets.

View davejlong's full-sized avatar

David Long davejlong

View GitHub Profile
@davejlong
davejlong / find_users.rb
Created February 3, 2014 16:01
Finding all user IDs for all Clients that the current user is in
user.clients.map do |client|
client.users.pluck(:id)
end.flatten.uniq
Failure/Error: expect{ FileImporter.new }.not_to raise_error ArgumentError
ArgumentError:
`expect { }.not_to raise_error(SpecificErrorClass)` is not valid, use `expect { }.not_to raise_error` (with no args) instead
@davejlong
davejlong / gist:9555251
Created March 14, 2014 19:41
Playing with JavaScript `new Date()`
var d = new Date('2014-03-14');
@davejlong
davejlong / bad_hash_store.rb
Created April 7, 2014 20:14
Changing my thought process with Ruby
# Code is way too verbose
class HashStore
attr_writer :store
def store
@store ||= Hash.new
end
def add_value(scope, value)
it store.has_key?(scope) && store[scope].is_a?(Array)
@davejlong
davejlong / 2.0.0-p451.patch
Created April 28, 2014 18:13
Patch Ruby 2.0.0-p451 to support Readline-6.3+
diff --git a/ext/readline/extconf.rb b/ext/readline/extconf.rb
index 4920137..b351533 100644
--- ext/readline/extconf.rb
+++ ext/readline/extconf.rb
@@ -19,6 +19,10 @@ def readline.have_func(func)
return super(func, headers)
end
+def readline.have_type(type)
+ return super(type, headers)
@davejlong
davejlong / README.md
Last active August 29, 2015 14:01
Color Categories
@davejlong
davejlong / delete_branches.rb
Created June 4, 2014 14:52
Remove all feature and hotfix branches from local repo
`git branch -l`
.split("\n").map { |branch| branch.strip }
.select { |branch| branch[/(feature|hotfix)\//] }
.each { |branch| `git branch -d #{branch}` }
@davejlong
davejlong / pre-commit.sh
Last active August 29, 2015 14:02
Runs the `develop` rake task before allowing a user to commit.
#!/bin/bash
# Lets us read from the keyboard
exec < /dev/tty
bundle exec rake develop
passed=$?
if [ $passed -ne 0 ]
then
POST /cdndata HTTP/1.1
Host: c.xkcd.com
Connection: keep-alive
Content-Length: 9265
Cache-Control: no-cache
Pragma: no-cache
Accept: */*
Origin: http://xkcd.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36 OPR/22.0.1471.50
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
@davejlong
davejlong / netrestart.sh
Created October 3, 2014 14:47
Restart interface on Ubuntu now that they've disabled `service networking restart`
#!/bin/bash
iface=$1
echo "Restarting $iface"
ifdown $iface
sleep 5
ifup $iface