Skip to content

Instantly share code, notes, and snippets.

View oafridi's full-sized avatar

Osman oafridi

  • San Francisco, California
View GitHub Profile
# Params: state, id, limit, offset
class Api::NearbySchoolsController < ApplicationController
before_filter :require_school
def show
get_array_of_nearby_school_hashes()
end
def limit
return 3 unless params[:limit]
@oafridi
oafridi / prune_branches.sh
Created August 12, 2020 21:43
prune branches
DRY_RUN='TRUE'
ECHO='echo'
for branch in `git branch -r --merged | grep -v HEAD`; do
if [[ "$(git log $branch --since "3 months ago" | wc -l)" -eq 0 ]]; then
local_branch_name=$(echo "$branch" | sed 's/remotes\/origin\///')
$ECHO git push origin --delete $local_branch_name
fi
done > dry_run.txt
@oafridi
oafridi / aoc_day_1
Created June 14, 2019 20:47
AOC Day One
# O(n)
def resulting_freq(collection, initial_value = 0)
collection.inject(initial_value) do |final_value, line|
final_value += line.to_i
end
end
p resulting_freq([+1, +1, +1]) == 3
p resulting_freq([+1, +1, -2]) == 0
require 'open-uri'
require 'launchy'
resp = open('http://www.bbc.co.uk/radio1/chart/singles/print').read
data = resp.scan(/<td>(.*)<\/td>/).flatten
rows = data.each_slice(6).map {|row| row}
songs = []
rows.each do |row|
@oafridi
oafridi / pre-commit-rspec.sh
Last active November 6, 2015 17:15
pre commit hook for rspec focus
#!/bin/sh
exec 1>&2
if [ $? -eq 0 ]
then
echo "Error: attempted to check in an rspec *_spec.rb file which contains a focus."
echo "Do \"find . -name '*_spec.rb' | xargs egrep '^\s*(describe|it|context)\b.*focus'\" to find out."
exit 1
fi
@oafridi
oafridi / gist:b0cece38c945023e4c86
Created November 6, 2015 17:02
pre commit to run multiple pre commit scripts
#!/bin/sh
for hook in "pre-commit-byebug" "pre-commit-rspec";
do
sh "$(pwd)/.git/hooks/$hook"
if [ $? -ne 0 ]; then
exit 1
fi
done
@oafridi
oafridi / gist:f3f9b24bc71150ce3ca2
Created July 9, 2015 17:59
before vs before each vs before all
require 'spec_helper'
$count = 0
$count_each = 0
$count_all = 0
shared_examples_for "before :each" do
it { should == 1 }
it { should == 2 }
end

true and false vs. "truthy" and "falsey" (or "falsy") in Ruby, Python, and JavaScript

Many programming languages, including Ruby, have native boolean (true and false) data types. In Ruby they're called true and false. In Python, for example, they're written as True and False. But oftentimes we want to use a non-boolean value (integers, strings, arrays, etc.) in a boolean context (if statement, &&, ||, etc.).

This outlines how this works in Ruby, with some basic examples from Python and JavaScript, too. The idea is much more general than any of these specific languages, though. It's really a question of how the people designing a programming language wants booleans and conditionals to work.

If you want to use or share this material, please see the license file, below.

Update

gem 'guard'
gem 'guard-rspec', require: false
gem 'guard-livereload', require: false
# then run
guard init
@oafridi
oafridi / aliases
Last active August 29, 2015 14:08
alias la='ls -altr'
alias gst='git status'
alias gco='git checkout'
alias gc='git commit'
alias rdc='bundle exec rake db:create'
alias rdm='bundle exec rake db:migrate'
alias rdd='bundle exec rake db:drop'
alias be='bundle exec'
alias rdm='bundle exec rake db:migrate'
alias rdc='bundle exec rake db:create'