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".
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" => { |
curl -i -H "X-Spree-Token: YOUR_TOKEN_ID" http://0.0.0.0:3000/api/products.json
curl -i -H "X-Spree-Token: YOUR_TOKEN_ID" http://0.0.0.0:3000/api/products/706676762.json
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
- Don't design a Model to be coupled to an API
- Create a Service that talks to both your Model and the API
- 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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:
OlderNewer