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
@taylonr
taylonr / ReturnVal
Created February 20, 2012 17:30
PetaPoco Stored Procedure Return Value
var sql = new Sql().Append("declare @@result int")
.Append("exec GetData @userId, @date",
new {userId = userId, @date = DateTime.Now})
.Append("select @@result);
var ret = Database.ExecuteScalar<int>(sql);
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)
{
{
"_id": "Tournament",
"Name": "Tournament",
"Records": [
{
"_id": "0329201309:57:17.231",
"Date": {
"$date": "2013-03-23T14:55:25.856Z"
},
"Note": "0-2 Gi & 0-2 NoGi at Sasquatch Open"
public class User
{
public string Email {get; set;}
public string FirstName {get; set;}
public string LastName {get; set;}
public string Password {get; set;}
}
public class UserLogic
{