Skip to content

Instantly share code, notes, and snippets.

View jerhinesmith's full-sized avatar

Justin Rhinesmith jerhinesmith

View GitHub Profile
@jerhinesmith
jerhinesmith / ruby.yml
Created August 14, 2023 23:45 — forked from jcypret/ruby.yml
Ruby CI (RSpec + CodeClimate) using GitHub Actions
name: build
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
@jerhinesmith
jerhinesmith / sock.rb
Created December 4, 2022 00:16
Sock Probability
total_runs = 100_000_000
seven_socks_without_match = 0
total_runs.times do |run|
dryer = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7, 7].shuffle
picked = []
iterations = 0
Atlanta Hawks 🐥
Boston Celtics 🍀
Brooklyn Nets 🏙
Charlotte Hornets 🐝
Chicago Bulls 🐮
Cleveland Cavaliers ⚔
Dallas Mavericks 🐴
Denver Nuggets 🏔
Detroit Pistons 🚗
Golden State Warriors 💦
@jerhinesmith
jerhinesmith / download.rb
Created August 14, 2015 16:23
Grab all NBA team logos
#!/usr/bin/env ruby
require 'open-uri'
teams = {
atl: 'hawks',
bkn: 'nets',
bos: 'celtics',
cha: 'hornets',
chi: 'bulls',
@jerhinesmith
jerhinesmith / nginx_sample
Created November 20, 2012 03:10
sample nginx configuration
server {
listen 80;
server_name localhost;
rails_env production;
root /var/www/myapp/current/public;
passenger_enabled on;
index index.html index.htm;
client_max_body_size 50M;
if (-f $document_root/system/maintenance.html) {
@jerhinesmith
jerhinesmith / nginx
Created November 20, 2012 02:34
Init script for nginx
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
@jerhinesmith
jerhinesmith / gist:2018326
Created March 11, 2012 21:48
Simple has_many :through
###########
# Classes #
###########
class Group < ActiveRecord::Base
has_many :memberships,
:class_name => 'GroupUser'
has_many :users,
:through => :memberships,
:source => :user
user system total real
YAML::dump 78.990000 0.360000 79.350000 ( 79.257540)
to_json 2.150000 0.000000 2.150000 ( 2.143407)
YAML::load 11.370000 0.010000 11.380000 ( 11.368933)
JSON.parse 2.680000 0.050000 2.730000 ( 2.721737)
user system total real
YAML::dump 1.530000 0.020000 1.550000 ( 1.543227)
to_json 0.060000 0.000000 0.060000 ( 0.058312)
YAML::load 0.370000 0.000000 0.370000 ( 0.375445)
JSON.parse 0.070000 0.000000 0.070000 ( 0.075179)
@jerhinesmith
jerhinesmith / gist:1108427
Created July 27, 2011 00:31
yaml/json serialization
require 'benchmark'
require 'json'
require 'yaml'
iterations = 10_000
message = {:to => 'Justin', :from => 'Andres', :subject => 'Foosball Game', :body => "Hey, sorry that I left without at least asking anyone if they wanted to play a quick game of foosball. That was really dumb. Next time I won't be dumb about that."}
message_yaml = YAML::dump(message)
message_json = message.to_json