Skip to content

Instantly share code, notes, and snippets.

View auth_controller.ex
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
View compile.ex
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)
View controller.ex
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 Jul 8, 2016
BencheeMacro
View macro.ex
defmodule MyMacros do
defmacro benchee(suite, name, function) do
quote do
benchee.benchmark(unquote(suite), unquote(name), unquote(function))
end
end
end
View complete_pipeline.ex
Path.join("#{:code.priv_dir(:random_tweets)}", filename)
|> RandomTweets.File.get_line
|> ExTwitter.update
@taylonr
taylonr / file.ex
Last active Jun 20, 2016
Get random line from a file
View file.ex
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
View FizzBuzzNoAbbreviations.cs
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)
{
View Production
$scope.isBalancePositive = function(){
if($scope.balance > 0){
return true;
}
}
View After Refactor
describe('User Service...', function(){
var userService,
customerService,
scope;
beforeEach(inject(function(testHelper){
userService = testHelper.setUpMocksWithSpies('UserService');
customerService = testHelper.setUpMocksWithSpies('CustomerService');
View activity.tests.js
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);