Skip to content

Instantly share code, notes, and snippets.

hsh = {
'a' => 1,
'b' => 2,
'c' => 3
}
hsh = Hash.new
hsh['a'] = 1
hsh['b'] = 2
hsh['c'] = 3
@QuillyT
QuillyT / Blocks in Ruby
Last active March 19, 2021 17:36
Blocks in Ruby
def get_items_from_api(page=0, page_size=10)
start = page * page_size
entire_list = (1..30).to_a
slice_of_list = entire_list.slice(start, page_size)
slice_of_list
end
def run_0
@QuillyT
QuillyT / gist:0a71d32ff29fd25365181c39988f2b6b
Created October 26, 2020 13:55
gem_make.out for the fast_trie gem
Building native extensions. This could take a while...
ERROR: Error installing fast_trie:
ERROR: Failed to build gem native extension.
current directory: /Users/quentintai/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/fast_trie-0.5.1/ext/trie
/Users/quentintai/.rbenv/versions/2.5.1/bin/ruby -r ./siteconf20201026-42589-1ld0gyx.rb extconf.rb
creating Makefile
current directory: /Users/quentintai/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/fast_trie-0.5.1/ext/trie
make "DESTDIR=" clean
export PS1="\W\[\033[32m\]\$(parse_git_branch)\[\033[00m\]🙊 "
# Git branch in prompt.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
source /usr/local/etc/bash_completion.d/git-completion.bash
alias cdp="cd ~/Projects/gSchool/projects"
def create_enrollments_hash(district, year, percentage)
build_or_check_hash(enrollments, district, year)
unless percentage == nil
enrollments[district][type][year] = percentage
end
end
def build_or_check_hash(a_hash, *some_keys)
temp_hash = a_hash
some_keys.each do |key|
@QuillyT
QuillyT / argv.rb
Created October 20, 2015 00:49
Playing with console arguments# This is going to show you what the ARGV values do variable = ARGV p variable puts ARGV[0] puts ARGV[1] puts ARGV[2] thing = (ARGV[7] == nil) puts thing.inspect
# This is going to show you what the ARGV values do
#
# Just try some of these in console to see what happens:
# $ ruby argv.rb 1
# $ ruby argv.rb 1 2
# $ ruby argv.rb hi hello
# $ ruby argv.rb 1 hi message.txt
variable = ARGV
p variable