Skip to content

Instantly share code, notes, and snippets.

View Iknewthisguy's full-sized avatar

Chris Bolton Iknewthisguy

View GitHub Profile
@Iknewthisguy
Iknewthisguy / gist:55ce2cf0516a89ee5c1c9009cadfb8e7
Last active October 23, 2017 15:47
Two column sorting and grouping
Unsorted
[
{number: 7, id: "abc"},
{number: 1, id: "def"},
{number: 4, id: "abc"},
{number: 0, id: "def"},
{number: 3, id: "abc"},
{number: 5, id: "def"},
{number: 6, id: "abc"},
cities.csv
city, state
charlotte,
raleigh,
boise,
chicago,
albany,
irvine,
austin,
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/christopherjbolton/.rbenv/versions/2.0.0-p353/bin/ruby extconf.rb
checking for main() in -lpthread... yes
checking for main() in -lobjc... yes
Warning! Unable to load libv8 ~> 3.16.14.
checking for v8.h... yes
creating Makefile
make "DESTDIR="
= f.input :state, as: :select, collection: [["All", ''], ["Pending", :pending], ["Active", :active]], include_blank: false, input_html: {value: params[:query].try(:[], :state)}
@Iknewthisguy
Iknewthisguy / gist:10223270
Last active August 29, 2015 13:58
Ordering association
has_many :public_photos,
-> { where(albums: {shared: 'public'})},
order: "created_at DESC",
through: :albums,
class_name: Photo,
source: :photos
@Iknewthisguy
Iknewthisguy / gist:9895342
Created March 31, 2014 15:47
Testing recursive player turn
# code
def take_turn(game, mark)
player_choice = get_player_choice
if game.positions.include? player_choice
self.turns << player_choice
game.print_turn(game.board, player_choice, mark)
game.reduce_positions(game.positions, player_choice)
else
puts "Please select one of the available positions. Which are #{game.positions}"
def zero
0
end
def one
1
end
def two
2
end
def three
@Iknewthisguy
Iknewthisguy / gist:7636397
Created November 25, 2013 04:31
Complicated where
Song has redemptions
Redemptions have multiple types. Redemptions have expiration dates.
Songs can also be deleted
I want to collect all Songs that are deleted OR that have one or more redemptions with a promoter type of 'promotion' that are not expired.
What I've got so far ...
Song.where( deleted_at: nil)
@Iknewthisguy
Iknewthisguy / gist:7408040
Created November 11, 2013 04:49
Nested Hash Example
{"id"=>68721,
"quicktime"=>
[{"name"=>"Teaser",
"sources"=>
[{"size"=>"480p",
"source"=>
"http://trailers.apple.com/movies/marvel/ironman3/ironman3-tlr1-m4mb0_h480p.mov"},
{"size"=>"720p",
"source"=>
"http://trailers.apple.com/movies/marvel/ironman3/ironman3-tlr1-m4mb0_h720p.mov"},
@Iknewthisguy
Iknewthisguy / gist:6875557
Last active December 24, 2015 22:49
tiered reducing
available_funds = {
gifted_credits: 15,
earned_credits: 25,
purchased_credits: 35
}
credits = available_funds.values.reduce(:+)
price = 50
unless price > credits