Skip to content

Instantly share code, notes, and snippets.

View jrhorn424's full-sized avatar
🌟
Always be dreaming

Jeffrey Horn jrhorn424

🌟
Always be dreaming
View GitHub Profile
# Encapsulate the configuration DSL pattern.
#
# Any `X=(value)` setter method on the given +obj+ is translated into `X(value)` method
# in the context of this object.
class ConfigDSL < BasicObject
def initialize(obj, &config)
@self = obj
call(&config)
end
@jrhorn424
jrhorn424 / simple_nuke_pave.rake
Created October 21, 2014 18:27
Simply drop your database and start again
# lib/tasks/db.rake
# execute me with rake db:nuke_pave
namespace :db do
desc "drops, creates, migrates, and seeds database"
unless Rails.env == "Production"
task :nuke_pave => %w(environment db:drop db:create db:migrate db:seed) do
# If you have a sample file that creates data for you to play with locally:
# Rake::Task["db:sample"].execute if Rails.env == "development"
puts "Nuke and pave of #{Rails.env} complete."
body {
width: 100%;
height: 500px;
margin: 0;
padding: 0;
text-align: center;
}
body:before {
display: inline-block;
content: ' ';

Number to Ordinal

See full kata at codewars

Finish the function numberToOrdinal, which should take a number and return it as a string with the correct ordinal indicator suffix (in English). That is:

  • numberToOrdinal(1) ==> '1st'
  • numberToOrdinal(2) ==> '2nd'
  • numberToOrdinal(3) ==> '3rd'
  • numberToOrdinal(4) ==> '4th'
@jrhorn424
jrhorn424 / keybase.md
Last active August 29, 2015 14:07
Keybase Proof

Keybase proof

I hereby claim:

  • I am jrhorn424 on github.
  • I am jrhorn (https://keybase.io/jrhorn) on keybase.
  • I have a public key whose fingerprint is EA9D 4FC3 908C 7657 08BB 2A11 A2D2 72CF F38D B3A7

To claim this, I am signing this object:

@jrhorn424
jrhorn424 / 0_reuse_code.js
Created August 15, 2014 21:11
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@jrhorn424
jrhorn424 / fizz.rb
Created August 13, 2014 19:01 — forked from ggilder/fizz.rb
messages = [nil, "Fizz", "Buzz", "FizzBuzz"]
acc = 810092048
(1..100).each do |i|
c = acc & 3
puts messages[c] || i
acc = acc >> 2 | c << 28
end
# Explanation
#

Commands examples

If the namespace is not used then the commands will perform on top of the default database. bundle exec rake db:create bundle exec rake db:migrate

By using the namespace we are going to use all the configuration for our alternate DB. bundle exec rake store:db:create bundle exec rake store:db:migrate

require 'active_record'
require 'arel'
# Ruby-like syntax in AR conditions using the underlying Arel layer (Rails >= 3.0).
#
# What you would usually write like this:
#
# User.where(["users.created_at > ? AND users.name LIKE ?", Date.yesterday, "Mary"])
#
# can now be written like this:

Command Line Tricks

  • !! Repeat Previous Command
  • !-1 Repeat Previous Command
  • !-2 Repeat 2nd Previous Command
  • !ps Execute Previous Command STARTING WITH ps
  • !^ First Argument From Previous Command
  • !:2 2nd Argument From Previous Command
  • !$ Last Argument From Previous Command
  • !!:$ Last Argument From Previous Command