This file contains hidden or 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 Standard do | |
def fib(0), do: 0 | |
def fib(1), do: 1 | |
def fib(n), do: fib(n-1) + fib(n-2) | |
end | |
defmodule Optimized do | |
def fib(0), do: 0 | |
def fib(1), do: 1 | |
def fib(1, current, _), do: current |
This file contains hidden or 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
var gulp = require('gulp'); | |
var concat = require('gulp-concat'); | |
var print = require('gulp-print'); | |
var bowerFiles = require('main-bower-files'); | |
var filter = require('gulp-filter'); | |
var sass = require('gulp-sass'); | |
var flatten = require('gulp-flatten'); | |
var jsFilter = filter('**/*.js'); | |
var cssFilter = filter('**/*.css'); |
This file contains hidden or 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 MacroExp do | |
defmacro attr_accessor(atom) do | |
getter = String.to_atom("get_#{atom}") | |
setter = String.to_atom("set_#{atom}") | |
quote do | |
def unquote(getter)(data) do | |
data |> Map.from_struct |> Map.get(unquote(atom)) | |
end | |
def unquote(setter)(data, value) do | |
data |> Map.put(unquote(atom), value) |
This file contains hidden or 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
import Foundation | |
extension Int { | |
func timesMap(closure: (Int) -> AnyObject) -> Array<AnyObject> { | |
var array: AnyObject[] = [] | |
for x in 1...self { | |
array += closure(x) | |
} | |
return array; | |
} |
This file contains hidden or 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 Controller.Main do | |
use Weber.Controller | |
render_when_raise :unauthorized, {:text, 401, "Unauthorized.", []} | |
layout false | |
def action(_, conn) do | |
{:render, [project: "simpleTodo"], []} |
This file contains hidden or 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 JSONMapBuilder do | |
def to_map(list) when is_list(list) and length(list) > 0 do | |
case list |> List.first do | |
{_, _} -> | |
Enum.reduce(list, %{}, fn(tuple, acc) -> | |
{key, value} = tuple | |
Map.put(acc, binary_to_atom(key), to_map(value)) | |
end) | |
_ -> | |
list |
This file contains hidden or 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
CGPoint centroidOfPoints(const CGPoint* points, int pointCount) { | |
CGPoint centroid = CGPointMake(0, 0); | |
double x0, y0, x1, y1, partialArea; | |
double signedArea = 0.0; | |
for (int index = 0; index < pointCount; index++) { | |
int nextIndex = (index == pointCount-1) ? 0 : index+1; | |
x0 = points[index].x; | |
y0 = points[index].y; |
This file contains hidden or 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
- (void)tapCellWithName:(NSString *)name inTableViewWithAccessibilityLabel:(NSString *)accessibilityLabel { | |
[tester runBlock:^KIFTestStepResult(NSError *__autoreleasing *error) { | |
UITableView *tableView = (UITableView *)[tester waitForViewWithAccessibilityLabel:accessibilityLabel]; | |
NSIndexPath *foundIndexPath = nil; | |
for (int section = 0; section < tableView.numberOfSections; section++) { | |
for (int row = 0; row < [tableView numberOfRowsInSection:section]; row++) { | |
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section]; | |
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; | |
if ([cell.textLabel.text isEqualToString:name]) { | |
foundIndexPath = indexPath; |
This file contains hidden or 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
long long ago; /* in a galaxy far far away */ | |
// Replaces with spaces the braces in cases where braces in places cause stasis | |
$str = str_replace(array("\{","\}")," ",$str); | |
#define TRUE FALSE //Happy debugging suckers | |
// sometimes I believe compiler ignores all my comments | |
// I am not sure if we need this, but too scared to delete. |
This file contains hidden or 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
- (void)animateConstraints { | |
[self setNeedsUpdateConstraints]; | |
[UIView animateWithDuration:0.4 animations:^{ | |
[self layoutIfNeeded]; | |
}]; | |
} |