Skip to content

Instantly share code, notes, and snippets.

View logicmason's full-sized avatar

Mark Wilbur logicmason

View GitHub Profile
@logicmason
logicmason / auth_controller.ex
Created December 19, 2016 16:43
Generate tokens for Twilio Programable video
# my_app/web/controllers/auth_controller.ex
defmodule MyApp.AuthController do
use MyApp.Web, :controller
import Ecto.Query
alias MyApp.TwilioToken
# Connect this to a route for /token:identity
def token(conn, %{"identity" => identity}) do
token = TwilioToken.for_video(identity)
json conn, %{token: token, identity: identity}
// Mini-bandit
const explorationRatio = 0.1;
// example levers array
/* [{name: 'control', trials: 412, conversions: 113, revenue: 22260},
{name: 'noCarousel', trials: 723, conversions: 298, revenue: 45390},
{name: 'crazyCarousel', trials: 19, conversions: 11, revenue: 6600}
]
*/
@logicmason
logicmason / handlebars-helper.js
Last active August 29, 2015 14:18
Why doesn't Handlebars have something like this built-in?
/** Because Handlebars sucks and won't let you iterate with @index
* Use this lookup helper to do things with the automatic @index var inside loops
*
* Usage example: (Get the item at @index each iteration through foo)
* {{#each foo}}
* <div>{{someProp}}</div>
* <div>{{lookup ../dailyStat @index}}</div>
* {{/each}}
*
* Block usage example: (get the item at @index in monthlyUniqueCustomers and then use its subcomponents
{
"auto_complete_commit_on_tab": true,
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"folder_exclude_patterns":
[
".svn",
".git",
".hg",
"CVS",
"node_modules"
@logicmason
logicmason / .bash_profile
Last active August 29, 2015 14:12
.bash_profile
export PKG_CONFIG_PATH=/usr/X11/lib/pkgconfig/:/usr/X11/lib/pkgconfig:
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
source /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash
source /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=true
#export PS1='\u@\h:\w$(__git_ps1)$ '
@logicmason
logicmason / yc.js
Last active June 18, 2021 01:46
Y combinator in JavaScript and factorial function example (recursion with all anonymous functions)
var Y = function(proc) {
return (function(x) {
return proc(function(y) { return (x(x))(y);});
})(function(x) {
return proc(function(y) { return (x(x))(y);});
});
};
var factgen = function(fact) {
return function(n) {
@logicmason
logicmason / gist:7315562
Last active December 27, 2015 10:59
Sieve of Eratosthenes in Scala, using lazy evaluation. Example code in lines 4-5 prints out first 15 primes
def sieve(s: Stream[Int]): Stream[Int] = {
s.head #:: sieve(s.tail.filter(_ % s.head != 0))
}
val primes = sieve(Stream.from(2)) //infinite lazy stream
println((primes take 15).toList)
@logicmason
logicmason / Preferences.sublime-settings
Last active December 27, 2015 08:39
My Sublime Text 2 user preferences will automatically trim trailing whitespace on every save, and the Node.js build system allows running JavaScript files by hitting command-b. If your Node installation is in a different location you may have to change the path in the "cmd" line.
{
"font_size": 13.0,
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_automatic_white_space": true,
"trim_trailing_white_space_on_save": true,
"use_tab_stops": true
}
@logicmason
logicmason / gist:7267772
Created November 1, 2013 16:16
This nQueens solution in Scala is surprisingly verbose compared to the JS versions I've seen. I'm still a beginner though, working through the Coursera class by Martin Odersky.
object nQueens {
def queens(n: Int): Set[List[Int]] = {
def placeQueens(k: Int): Set[List[Int]] =
if (k == 0) Set(List())
else
for {
queens <- placeQueens(k - 1)
col <- 0 until n
if isSafe(col, queens)
} yield col :: queens