Skip to content

Instantly share code, notes, and snippets.

View joshnuss's full-sized avatar
🤘

Joshua Nussbaum joshnuss

🤘
View GitHub Profile
@henrik
henrik / hash_deep_diff.rb
Created July 14, 2009 08:38
Recursively diff two Ruby hashes.
# Recursively diff two hashes, showing only the differing values.
# By Henrik Nyh <http://henrik.nyh.se> 2009-07-14 under the MIT license.
#
# Example:
#
# a = {
# "same" => "same",
# "diff" => "a",
# "only a" => "a",
# "nest" => {
@nazgob
nazgob / ctags.setup
Created January 6, 2012 13:44
ctags setup on mac
# you have ctags but it does not work...
$ ctags -R --exclude=.git --exclude=log *
ctags: illegal option -- R
usage: ctags [-BFadtuwvx] [-f tagsfile] file ...
#you need to get new ctags, i recommend homebrew but anything will work
$ brew install ctags
#alias ctags if you used homebrew
$ alias ctags="`brew --prefix`/bin/ctags"
@bclinkinbeard
bclinkinbeard / README.md
Created August 21, 2012 01:35
AngularJS Response Interceptor Demo

This is a simple demo of how to create and use a Response Interceptor in AngularJS. In this case we are using the interceptor to convert the objects created from a JSON data load into typed instances of a custom "class".

@jcowhigjr
jcowhigjr / spree-api-rest-examples.md
Created November 5, 2012 23:58
Spree API REST Examples

Products

index of products 25 first

curl -i -H "X-Spree-Token: YOUR_TOKEN_ID" http://0.0.0.0:3000/api/products.json

Show a product

curl -i -H "X-Spree-Token: YOUR_TOKEN_ID" http://0.0.0.0:3000/api/products/706676762.json

Modify a product

curl -i -X PUT -H "X-Spree-Token: YOUR_TOKEN_ID" -d "product[name]=Headphones" http://0.0.0.0:3000/api/products/706676762.json

@nicholasjhenry
nicholasjhenry / gist:4070557
Created November 14, 2012 05:56
Deconstructing the Framework (Gary Bernhardt)

Design in the Small

  • Don't design a Model to be coupled to an API
  • Create a Service that talks to both your Model and the API

Service Wrapper Record

  • You have services, stateless objects that talk to the application
  • You have records, objects that talk to the database
  • And you have Wrappers, a thin class for a narrow interface to an API
include Math;R1=1.0; R2=2.0;K2=5.0
SS=40;K1=SS*K2*3/(8*(R1+R2));def rf(a, b)
cosA=cos(a);sinA=sin(a);cosB=cos(b);sinB=sin(b)
o=Array.new(SS).fill{Array.new(SS).fill(' ')};b=Array.
new(SS).fill{ Array.new(SS).fill(0)}; t=0.0;while t<2*PI
cost=cos(t);sint=sin(t);p=0.0;while p<2*PI;cosp=cos(p);sinp=
sin(p);cx=R2+R1*cost;cy=R1* sint;x=cx*(cosB*cosp+sinA*
sinB*sinp)-cy*cosA*sinB; y=cx*(sinB*cosp-sinA*##
cosB*sinp)+cy*cosA*cosB ;z=K2+cosA*cx*sinp+cy*
sinA;ooz=1/z;xp=(SS/2+K1* ooz*x).to_i ;yp= (SS/2-
defmodule Curried do
defmacro defc({name, _, args}, [do: body]) do
curried_args = Enum.map(Enum.with_index(args), fn({_, index}) ->
Enum.take(args, index + 1)
end)
for a <- curried_args do
if a == Enum.at(curried_args, Enum.count(curried_args) - 1) do
quote do
def unquote(name)(unquote_splicing(a)) do
unquote(body)
defmodule R do
def sample_file_inefficient(path, count) do
s = File.stream!(path, [], :line)
sample = Enum.take(s, count) |> List.to_tuple
Stream.drop(s, count)
|> Stream.with_index
|> Enum.reduce(sample, fn {line, index}, sample ->
case random(index) do
r when r < count -> put_elem(sample, r, line)
@holsee
holsee / btree.ex
Last active January 11, 2020 13:17
BTree in Elixir
defmodule BTree do
defstruct tree: nil
def new(e), do: %BTree{tree: {e, nil, nil}}
def insert(%BTree{tree: root}, element) do
%BTree{tree: do_insert(root, element)}
end
defp do_insert(nil, element) do
@abunsen
abunsen / spec.md
Last active August 29, 2015 14:21
TicTacToe spec

So I built an algorithm that tries to lose tictactoe no matter what. If you'd like to battle your algorithm against mine, I think it would be fun. This is the spec of what your server should accept & return. If you built an algorithm that can beat it, please tweet me @bunsen.

Your server should accept GET requests with the following parameters:

  • row
  • col
  • mark
  • grid - will be a url encoded array, like this: [["x",%20"x",%20nil],%20[nil,%20nil,%20"o"],%20[nil,%20"o",%20nil]]

It should return JSON that looks like this: