Skip to content

Instantly share code, notes, and snippets.

View rubysolo's full-sized avatar

Solomon White rubysolo

View GitHub Profile
@rubysolo
rubysolo / config.exs
Created October 11, 2015 19:35 — forked from limhoff-r7/config.exs
nginx + phoenix configuration to server phoenix behind nginx at path 'phoenix'. nginx rewrites incoming URLs to strip the /phoenix, while the config.exs for phoenix ensures URLs are prefixed with /phoenix using the config.url.path
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
#
# This configuration file is loaded before any dependency and
# is restricted to this project.
use Mix.Config
# Configures the namespace used by Phoenix generators
config :my_app,
app_namespace: MyApp
@rubysolo
rubysolo / data.js
Created March 1, 2017 00:07 — forked from NPashaP/data.js
Stacked Density and Quantile Graphs
var dqData=[];
dqData.push({title:'Product Groups',
mean:0.0393,
dP:[
['GROUP01',-0.0435,32937],
['GROUP10',-0.2651,132],
['GROUP11',-0.0694,1164],
['GROUP12',0.0345,17127],
['GROUP13',-0.0288,8858],
['GROUP18',-0.3741,46],
@rubysolo
rubysolo / file_size_hist.sh
Created December 12, 2016 17:56
File size histogram
find . -type f -print0 | xargs -0 ls -l | awk '{ n=int(log($5)/log(2)); if (n<10) { n=10; } size[n]++ } END { for (i in size) printf("%d %d\n", 2^i, size[i]) }' | sort -n | awk 'function human(x) { x[1]/=1024; if (x[1]>=1024) { x[2]++; human(x) } } { a[1]=$1; a[2]=0; human(a); printf("%3d%s: %6d\n", a[1],substr("kMGTEPYZ",a[2]+1,1),$2) }'
@rubysolo
rubysolo / router.ex
Last active March 7, 2016 03:43
CORS with Phoenix
defmodule App.Router do
use Phoenix.Router
resources "users", Controller.Users
options "/users", Controller.Users, :options
end
@rubysolo
rubysolo / up-and-running-with-edeliver-on-do.md
Created October 7, 2015 22:45 — forked from mattweldon/up-and-running-with-edeliver-on-do.md
Getting Elixir / Phoenix running on Digital Ocean with edeliver

Build Server

  • Go to Digital Ocean
  • Create new droplet
  • London
  • Ubuntu
  • No apps
  • Add SSH keys
@rubysolo
rubysolo / etc_init.d_unicorn_example.co.uk
Created October 27, 2011 20:04 — forked from scottlowe/etc_init.d_unicorn_example.co.uk
Ruby on Rails server setup on Ubuntu 11.04 with Nginx, Unicorn, Rbenv
#! /bin/bash
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the unicorn web server
# Description: starts unicorn
defrecord Card, suit: nil, rank: nil
defmodule Cards do
def create do
lc suit inlist [:H, :D, :C, :S],
rank inlist [:A, 2, 3, 4, 5, 6, 7, 8, 9, 10, :J, :Q, :K] do
Card.new suit: suit, rank: rank, points: score(rank)
end
end
@rubysolo
rubysolo / tracy.coffee
Created December 16, 2013 18:10
add console log to each function invocation
falafel = require 'falafel'
fs = require 'fs'
raw = process.argv[2]
cooked = raw.replace(/\.js$/, '-trace.js')
counter = 0
src = fs.readFileSync(raw, encoding: 'utf8')
tracied = falafel src, (node) ->
module Enumerable
def remove(other)
base = self.dup
other.each { |i| base.delete_at(base.index(i) || base.length) }
base
end
end
irb(main):008:0> [1,1,2,3].remove([1,2])
=> [1, 3]
@rubysolo
rubysolo / spec_helper.rb
Created November 7, 2013 13:43
Workaround for rspec-fire "does not implement" errors with ActiveRecord models
# inside config.before(:suite)
ActiveRecord::Base.subclasses.each do |model_class|
columns = model_class.columns.map { |c| c.name.to_sym }
missing = columns - model_class.instance_methods
missing.each do |column|
model_class.send(:define_method, column) { |*args| super(*args) }
end
end