Skip to content

Instantly share code, notes, and snippets.

# Today's little useless tidbit converts a url's query string into a hash
# set of k/v pairs in a way that merges duplicates and massages empty
# querystring values
def qs_to_hash(query_string)
keyvals = query_string.split('&').inject({}) do |result, q|
k,v = q.split('=')
if !v.nil?
result.merge({k => v})
elsif !result.key?(k)
@josephchoe
josephchoe / sinatra_proxy
Created September 6, 2017 19:52 — forked from burgalon/ sinatra_proxy
Testing client side app (like BackboneJS) with Capybara, VCR, webmock, factory girl
Testing client side app (like BackboneJS) with Capybara, VCR, webmock, factory girl
@josephchoe
josephchoe / validate_facebook_signature.rb
Created September 8, 2017 17:47 — forked from schneems/validate_facebook_signature.rb
validate facebook signed_request in ruby
require 'base64'
def base64_url_decode(str)
str += '=' * (4 - str.length.modulo(4))
Base64.decode64(str.gsub("-", "+").gsub("_", "/"))
end # source: https://github.com/ptarjan/base64url/blob/master/ruby.rb
require 'hmac'
require 'hmac-sha2' ## used to decode facebook return values
# app/serializers/customer_serializer_spec.rb
class CustomerSerializer < ActiveModel::Serializer
attributes :customer_number, :email, :username
def customer_number
object.account_number
end
def merchant_id
@josephchoe
josephchoe / rails-new-bare
Last active June 13, 2019 17:08 — forked from thewoolleyman/rails-new-bare
command to generate a barebones no-js no-db rails app
#!/usr/bin/env bash
rails new --skip-javascript --skip-turbolinks --skip-keeps --skip-git --skip-bundle --skip-test --skip-coffee testing-rails $1
rails new --skip-keeps --skip-git --skip-bundle --skip-test --skip-action-mailer --skip-action-cable testing-rails --api
bundle exec rails new \
--skip-keeps \
--skip-git \
--skip-bundle \
@josephchoe
josephchoe / test_induced_design_damage.rb
Created September 22, 2017 20:28 — forked from dhh/test_induced_design_damage.rb
This is an extraction from Jim Weirich's "Decoupling from Rails" talk, which explained how to apply the hexagonal design pattern to make every layer of your application easily unit testable (without touching the database etc). It only seeks to extract a single method, the EmployeesController#create method, to illustrate the design damage that's …
# Original Rails controller and action
class EmployeesController < ApplicationController
def create
@employee = Employee.new(employee_params)
if @employee.save
redirect_to @employee, notice: "Employee #{@employee.name} created"
else
render :new
end
@josephchoe
josephchoe / 01_original.rb
Created September 22, 2017 21:48 — forked from patmaddox/01_original.rb
hexarch in rails
# Original Rails controller and action
class EmployeesController < ApplicationController
def create
@employee = Employee.new(employee_params)
if @employee.save
redirect_to @employee, notice: "Employee #{@employee.name} created"
else
render :new
end
# Created by .ignore support plugin (hsz.mobi)
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
@josephchoe
josephchoe / The Technical Interview Cheat Sheet.md
Created September 27, 2017 19:17 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
@josephchoe
josephchoe / bithack.cc
Created September 30, 2017 07:05 — forked from stephenLee/bithack.cc
bit manipulation tricks(collections)
/*
* Reference:
* http://www.quora.com/Computer-Programming/What-are-some-cool-bit-manipulation-tricks-hacks
* http://www.catonmat.net/blog/low-level-bit-hacks-you-absolutely-must-know/
*/
#include <iostream>
#include <string.h>
using namespace std;