Skip to content

Instantly share code, notes, and snippets.

View nickgartmann's full-sized avatar

Nick Gartmann nickgartmann

View GitHub Profile
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
source "/Users/nickgartmann/.rvm/scripts/rvm"
source "/Users/nickgartmann/.rvm/contrib/ps1_functions"
YELLOW="\[\033[3;33m\]"
PURPLE="\[\033[3;35m\]"
NO_COLOR="\[\033[0m\]"
RED="\[\033[3;31m\]"
@nickgartmann
nickgartmann / User.rb
Created December 10, 2013 17:36
Login that works with twitter and facebook Requires that users have facebook_id and twitter_id
class User < Sequel::Model
def facebook_access_token=(value)
return if value.nil?
facebook_user = User.get_facebook_user(value)
self.email = facebook_user["email"] if self.email.nil? && !facebook_user["email"].blank?
self.facebook_id = facebook_user["id"]
end
def self.get_facebook_user(access_token)
facebook_user_request = RestClient.get "https://graph.facebook.com/me", {:params=> {:access_token => access_token } }
@nickgartmann
nickgartmann / realtime.js
Created March 5, 2014 17:31
A bookmarklet for setting the favicon of google analytics to the number of people currently on your site. (Will break not update if not navigated to the real time page - I suggest leaving it sit as a pinned tab)
javascript:var thing=function(){var e=parseInt(document.getElementById("ID-overviewCounterValue").innerText);[].slice.call(document.querySelectorAll("link[type='image/x-icon']")).forEach(function(e){e.parentNode.removeChild(e)});var t=document.createElement("canvas");t.width=16;t.height=16;var n=t.getContext("2d");var r=function(){n.font="bold 10px sans-serif";n.fillText(e,e>9?2:4,12);var r=document.createElement("link");r.type="image/x-icon";r.rel="shortcut icon";r.href=t.toDataURL("image/x-icon");document.getElementsByTagName("head")[0].appendChild(r)};r()};setInterval(thing,1e3)
@nickgartmann
nickgartmann / clone-database
Last active August 29, 2015 13:59
Bash script to capture and clone a heroku database into a local development database.
if test -z $1 || test -z $2
then
printf "Usage: clone-database heroku-app-name database-name\n"
exit
fi
echo "Capturing backup"
heroku pgbackups:capture -e -a $1
echo "Pulling dump"
curl -o /tmp/$1-latest.dump `heroku pgbackups:url -a $1`
@nickgartmann
nickgartmann / Gemfile
Created June 24, 2014 14:45
Rake task to grab recently updated cordova projects from github
gem 'rest-client', '~> 1.6.7'
gem 'nokogiri'
@nickgartmann
nickgartmann / application.js
Created October 4, 2014 00:12
Stack trace when trying to use websockets on phoenix 0.4.1
var socket = new Phoenix.Socket("/ws");
socket.join("ship", "topic", {}, function(channel) {
channel.on("connect", function(message) {
console.log("joined")
})
});
defmodule Pew.Ship do
use Phoenix.Channel
:timer.apply_interval(1000, __MODULE__, :gc, [])
def gc() do
IO.puts "stuff"
end
def join(socket, "join", msg) do
@nickgartmann
nickgartmann / localdocker
Last active August 29, 2015 14:08
Put localdocker into your hosts file on OS X
#! /bin/bash
# Get the ip from boot2docker
boot2docker_ip=$(sudo -u $SUDO_USER boot2docker ip 2>&1 | awk '{ print $NF }' | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n//g')
hosts=`cat /etc/hosts | sed "s/^.*localdocker.*$//g"`
echo "$hosts" > /etc/hosts
echo "$boot2docker_ip localdocker" >> /etc/hosts
var socket = new Phoenix.Socket(PewMiddle.config.socketPath);
PewMiddle.requestGame = function(username, callback) {
socket.join(PewMiddle.config.channel, "lobby", {username: username}, function(channel) {
var player = null;
channel.on("player:created", function(message) {
player = message;
});
channel.on("game:created", function(game) {
callback(game.id, player);
17:06:25.586 [error] #PID<0.258.0> running Spacegame.Endpoint terminated
Server: localhost:4000 (http)
Request: GET /ws
** (exit) an exception was raised:
** (ErlangError) erlang error: [reason: %Protocol.UndefinedError{description: nil, protocol: String.Chars, value: %{"thin" => "one"}}, mfa: {Phoenix.Endpoint.CowboyHandler, :websocket_handle, 3}, stacktrace: [{String.Chars, :impl_for!, 1, [file: 'lib/string/chars.ex', line: 3]}, {String.Chars, :to_string, 1, [file: 'lib/string/chars.ex', line: 17]}, {Logger, :truncate, 2, [file: 'lib/logger.ex', line: 492]}, {Logger, :log, 3, [file: 'lib/logger.ex', line: 404]}, {Spacegame.GameChannel, :event, 3, [file: 'web/channels/game.ex', line: 44]}, {Phoenix.Channel.Transport, :dispatch, 4, [file: 'lib/phoenix/channel/transport.ex', line: 102]}, {Phoenix.Channel.Transport, :dispatch, 4, [file: 'lib/phoenix/channel/transport.ex', line: 67]}, {Phoenix.Transports.WebSocket, :ws_handle, 2, [file: 'lib/phoenix/transports/websocket.ex', line: 45]}], msg: {:text, "{\"cha