Skip to content

Instantly share code, notes, and snippets.

View johnknott's full-sized avatar
🎯
Focusing

John Knott johnknott

🎯
Focusing
View GitHub Profile
@johnknott
johnknott / elixir-gen-server.code-snippets
Last active March 12, 2022 11:39
VSCode snippet to help with creation of Elixir GenServers and addition of handle_call and handle_cast and related client API functions
{
"GenServer Template": {
"scope": "elixir",
"prefix": "gs",
"body": [
"defmodule ${1}.${2} do",
"\tuse GenServer",
"",
"\t# Client",
"",
require 'rubygems'
require 'google/api_client'
client = Google::APIClient.new(
application_name: 'Ruby Google Calendar Example',
application_version: '1.0.0')
calendar = client.discovered_api('calendar', 'v3')
key = Google::APIClient::PKCS12.load_key('./keys/creds.p12', 'notasecret')
asserter = Google::APIClient::JWTAsserter.new(
@johnknott
johnknott / ruby-google-contact.rb
Created September 15, 2014 19:13
Creating a Google Contact with Ruby
require 'rubygems'
require 'bundler/setup'
Bundler.require
refresh_token = 'REDACTED'
CLIENT_ID = 'REDACTED'
CLIENT_SECRET = 'REDACTED'
client = OAuth2::Client.new(CLIENT_ID, CLIENT_SECRET, {
:authorize_url => 'https://accounts.google.com/o/oauth2/auth',
apt-get install build-essential libssl-dev libcurl4-openssl-dev libreadline-gplv2-dev zlib1g-dev libxslt1-dev libxml2-dev
cd /usr/src
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p385.tar.gz
tar zxvf ruby-1.9.3-p385.tar.gz
cd ruby-1.9.3-p385
./configure
make && make install
cd ext/openssl
---
en-GB:
number:
currency:
format:
format: "%u%n"
unit: "£"
precision: 2
separator: '.'
delimiter: ','
@johnknott
johnknott / nodeinstall.sh
Created November 2, 2011 13:47
Node/NPM
#!/bin/sh
mkdir ~/local
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.zshrc
. ~/.zshrc
git clone git://github.com/joyent/node.git
cd node
./configure --prefix=~/local
make install
if [ -d ~/.oh-my-zsh ]
then
echo "\033[0;33mYou already have Oh My Zsh installed.\033[0m You'll need to remove ~/.oh-my-zsh if you want to install"
exit
fi
echo "\033[0;34mCloning Oh My Zsh...\033[0m"
/usr/bin/git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
echo "\033[0;34mLooking for an existing zsh config...\033[0m"
#!/bin/bash
echo -e "\e[1;36mUPDATING PACKAGES\e[00m"
echo "deb http://nginx.org/packages/debian/ squeeze nginx" | tee -a /etc/apt/sources.list
echo "deb-src http://nginx.org/packages/debian/ squeeze nginx" | tee -a /etc/apt/sources.list
apt-get --quiet --assume-yes update
echo -e "\e[1;36mINSTALLING PACKAGES\e[00m"
apt-get --assume-yes --allow-unauthenticated --quiet install build-essential bzip2 openssl libssl-dev libreadline6 libreadline6-dev libxml2-dev libxslt-dev libsqlite3-dev sqlite3 subversion vim zsh zlib1g zlib1g-dev nginx sudo git python libcurl4-openssl-dev libpcre3-dev mercurial libyaml-dev imagemagick
useradd -m -c "spree" -s /bin/bash spree
adduser spree sudo
curl http://betterthangrep.com/ack-standalone > /usr/bin/ack && chmod 0755 /usr/bin/ack
@johnknott
johnknott / boot.rb
Created June 30, 2011 20:09
Replacing "irb" with "pry" when using "padrino console"
# Add this to your boot.rb before Padrino.load!
# and add: gem 'pry'
# to your Gemfile and run bundle to install.
begin
require 'pry'
$VERBOSE = nil
IRB = Pry
$VERBOSE = false
rescue LoadError
@johnknott
johnknott / gist:1052539
Created June 28, 2011 23:55 — forked from jnunemaker/gist:217362
example of warden with sinatra
Warden::Manager.serialize_into_session{|user| user.id }
Warden::Manager.serialize_from_session{|id| User.get(id) }
Warden::Manager.before_failure do |env,opts|
# Sinatra is very sensitive to the request method
# since authentication could fail on any type of method, we need
# to set it for the failure app so it is routed to the correct block
env['REQUEST_METHOD'] = "POST"
end