Skip to content

Instantly share code, notes, and snippets.

View davestevens's full-sized avatar

Dave Stevens davestevens

View GitHub Profile
@davestevens
davestevens / client.rb
Last active August 29, 2015 14:06
OAuth2 with Refresh Token
require "oauth2"
require_relative "token"
module Api
class Client
def initialize(client_id:, client_secret:, endpoint:)
@client_id = client_id
@client_secret = client_secret
@endpoint = endpoint
end
<!DOCTYPE html>
<html>
<head>
<style>
.vertically_align {
width: 256px;
height: 256px;
overflow: hidden;
}
#!/usr/bin/env ruby
require "rubyXL"
require "pry"
require "json"
# define from input
@key_col = 0
@translation_col = 2
file = PATH_TO_FILE
@davestevens
davestevens / for_loops.js
Last active August 29, 2015 13:57
JS For Loops?
// Setup
var array = [];
for(var i = 0; i < 1000; ++i) { array.push(i); }
var totals = {};
var log = function (id, time) {
totals[id] = totals[id] ? totals[id] : [];
totals[id].push(time);
};
require 'logger'
$logger = Logger.new(STDOUT)
require 'active_support/cache'
$cache = ActiveSupport::Cache.lookup_store(:memory_store)
$cache.logger = $logger
$cache.clear
class EtagMiddleware
@davestevens
davestevens / gist:8596770
Created January 24, 2014 13:00
Turtle Roy
penup
lt 180
fd 50
lt 180
lt 90
fd 50
rt 90
pendown
repeat 360(sequence[lt 1, fd 1])
fd 150
describe clCreateContext do
let(:params) { nil }
subject { clCreateContext(params) }
context "when calling with nil mooses" do
let(:params) { mooses: nil }
its(:errcode_ret) { should == CL_INVALID_MOOSE }
end
end
@davestevens
davestevens / gist:5029577
Created February 25, 2013 12:42
Setup jshint in emacs
This seems to run quicker than the jshint-mode example (https://github.com/daleharvey/jshint-mode) as it doesn't set up a node server each time.
1. Install node and get jshint
$ brew install node
$ npm install -g jshint
2. Update PATH to point to Node Packagem Manager bin directory
@davestevens
davestevens / dec_to_str.pl
Created December 6, 2012 20:26
Convert decimal numbers to string and vice versa
#!/usr/bin/perl
use strict;
# Kind of useless script to convert numbers to their word equivalent and back
# Call dec_to_str() with a decimal value, returns a string containing the word equivalent
# eg. dec_to_str(123456) := one hundred and twenty three thousand four hundred and fifty six
# Call str_to_dec() with a number in words, returns decimal value
@davestevens
davestevens / crop.php
Created November 5, 2012 11:41
Remove whitespace from around image.
<?php
/* Crop images */
/* Find whitespace around image and remove */
$border = 5;
/* Get image */
$orig = getImage($argv[1]);