Skip to content

Instantly share code, notes, and snippets.

@taylonr
taylonr / auth_controller.ex
Created August 29, 2016 23:01
Auth Controller
defmodule UeberTest.AuthController do
use UeberTest.Web, :controller
plug Ueberauth
alias Ueberauth.Strategy.Helpers
def request(conn, _params) do
render(conn, "request.html", callback_url: Helpers.callback_url(conn))
end
def callback(%{assigns: %{ueberauth_failure: _fails}} = conn, _params) do
@taylonr
taylonr / compile.ex
Created July 8, 2016 12:15
Compile String
def compare(conn, params) do
first = params["code"]["first_snippet"]
second = params["code"]["second_snippet"]
code = """
defmodule Sample do
def benchee do
Benchee.init(%{time: 3})
|> Benchee.benchmark('first snippet', fn -> #{first} end)
|> Benchee.benchmark('second snippet', fn -> #{second} end)
@taylonr
taylonr / controller.ex
Created July 8, 2016 12:05
String Eval
def compare(conn, params) do
first = params["code"]["first_snippet"]
second = params["code"]["second_snippet"]
{val, _} = Code.eval_string("Benchee.init(%{time: 3})
|> Benchee.benchmark('First', fn -> #{first} end)
|> Benchee.benchmark('Second', fn -> #{second} end)
|> Benchee.measure
|> Benchee.statistics
|> BencheeWeb.Formatter.to_map")
@taylonr
taylonr / macro.ex
Last active July 8, 2016 12:03
BencheeMacro
defmodule MyMacros do
defmacro benchee(suite, name, function) do
quote do
benchee.benchmark(unquote(suite), unquote(name), unquote(function))
end
end
end
Path.join("#{:code.priv_dir(:random_tweets)}", filename)
|> RandomTweets.File.get_line
|> ExTwitter.update
@taylonr
taylonr / file.ex
Last active June 20, 2016 02:55
Get random line from a file
def get_line(path) do
path
|> File.read!
|> String.split(~r{\n})
|> Enum.map(&String.strip/1)
|> Enum.filter(fn x -> String.length(x) <= 140 end)
|> Enum.random
end
using UnsignedInteger = System.UInt16; // Sorry, I can't unabbreviate it on the RHS
// https://twitter.com/taylonr/status/712277308363542530
namespace FizzBuzz
{
class Program
{
static void Main(System.String[] args)
{
@taylonr
taylonr / Production
Created June 1, 2015 14:23
Fail First
$scope.isBalancePositive = function(){
if($scope.balance > 0){
return true;
}
}
@taylonr
taylonr / After Refactor
Last active August 29, 2015 14:21
Initial test
describe('User Service...', function(){
var userService,
customerService,
scope;
beforeEach(inject(function(testHelper){
userService = testHelper.setUpMocksWithSpies('UserService');
customerService = testHelper.setUpMocksWithSpies('CustomerService');
@taylonr
taylonr / activity.tests.js
Created May 12, 2014 01:50
underscore query
var _ = require('lodash'),
ActivityController = require('../../../controllers/activity.controller'),
FakeDatabase = [
{userId: '123', Name: 'First Activity', Records: [{Date: new Date(2014, 1, 1)}]},
{userId: '123', Name: 'Second Activity', Records: [{Date: new Date(2014, 2, 1)}]}];
require('underscore-query')(_);
ActivityController.Activity.find = function(findObject, callback){
var activities = _.query(FakeDatabase, findObject);