Skip to content

Instantly share code, notes, and snippets.

Phil Hansch phansch

Block or report user

Report or block phansch

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@henrik
henrik / 1-exhaustive_case_exact_match.rb
Last active Apr 15, 2019
Experimental Ruby exhaustive conditionals that raise if no branch matches. A bit like in e.g. Elm.
View 1-exhaustive_case_exact_match.rb
# This replaces conditions like: `case …; when …; when …; else raise "Nothing matched!"` if an exact match is all you need.
def cond(input, hash)
hash.fetch(input) { raise "No branch for #{input.inspect}!" }.call
end
input = :good
cond(input,
good: -> { puts "So good!" },
bad: -> { puts "So bad!" },
@jkcclemens
jkcclemens / travis_cache.md
Last active Aug 30, 2019
Rust and Travis CI cache
View travis_cache.md

Rust and Travis CI cache

Using Travis CI's cache is very useful and helps cut Rust job times way, way down. However, the way that the default caching for Cargo is set up means it will quickly bloat.

Travis currently checks ~/.cargo and target/ for any changes from the current cache after a build. There will always be changes in target/ if the source has changed, which it usually does when a Travis build runs. This means new incremental object files, fingerprints, and build script compilation files are being added to the cache every build.

@odigity
odigity / knex.js
Last active Aug 29, 2019
Wrapping a unit test in a transaction for easy cleanup with Knex.js
View knex.js
#!/usr/bin/node
const Promise = require('bluebird')
const config = require('./config.json')
const knex = require('./lib/knex')(config.database).connection()
const mock = () => ({ user_id: Math.floor(Math.random() * 999) + 1, payload_type: 'foo', attributes: JSON.stringify({}) })
const before = (t) => {
@phansch
phansch / yardoc_cheatsheet.md
Last active Apr 9, 2020 — forked from chetan/yardoc_cheatsheet.md
Improved YARD cheatsheet
View yardoc_cheatsheet.md
@CoryFoy
CoryFoy / analytics.rb
Last active Feb 14, 2020
An example of calling the Analytics API using machine creds and the V4 API from Ruby
View analytics.rb
require 'google/apis/analyticsreporting_v4'
require 'googleauth'
include Google::Apis::AnalyticsreportingV4
include Google::Auth
VIEW_ID = "12345678" #your profile ID from your Analytics Profile
SCOPE = 'https://www.googleapis.com/auth/analytics.readonly'
@client = AnalyticsReportingService.new
@zmalltalker
zmalltalker / gist:5900206
Last active Nov 3, 2016
Install ruby-install, chruby and ruby 1.9.3 on Centos - Install puppet - Run `puppet apply <(curl -S https://gist.github.com/zmalltalker/5900206/raw/b9d7c2263cef981a8384a4e2b513e67c70060436/gistfile1.pp)`
View gist:5900206
# chruby
# ruby-install
# ruby 1.9.3
# /etc/profile.d/chruby.sh
Exec {
path => ["/bin","/usr/bin", "/usr/local/bin"]
}
file { "/etc/profile.d/chruby.sh":
ensure => present,
@jordelver
jordelver / gist:5806460
Created Jun 18, 2013
Sharing files using netcat
View gist:5806460

Sharing files using netcat

The receiver

nc -l 5566 > data-dump.sql

Listen on port 5566 and redirect output to data-dump.sql

The sender

@tjh
tjh / character_set_and_collation.rb
Created Jan 31, 2012
Convert all Rails table column collation and character set
View character_set_and_collation.rb
#!/usr/bin/env ruby
# Put this file in the root of your Rails project,
# then run it to output the SQL needed to change all
# your tables and columns to the same character set
# and collation.
#
# > ruby character_set_and_collation.rb
DATABASE = ''
@mythz
mythz / xhr.js
Created Nov 2, 2011
Standalone jQuery-like Ajax Client
View xhr.js
//Adds $.xhr and jQuery-like $.ajax methods to the prescribed namespace.
//Inspired from David Flanagans excellent cross-platform utils http://www.davidflanagan.com/javascript5/display.php?n=20-1&f=20/01.js
//Includes underscore.js _.each and _.extend methods
//modified to behave like jQuery's $.ajax(), not complete.
(function($) {
var win=window, xhrs = [
function () { return new XMLHttpRequest(); },
function () { return new ActiveXObject("Microsoft.XMLHTTP"); },
function () { return new ActiveXObject("MSXML2.XMLHTTP.3.0"); },
function () { return new ActiveXObject("MSXML2.XMLHTTP"); }
@panthomakos
panthomakos / group.rb
Created Sep 20, 2011
Custom Error Messages in Ruby
View group.rb
class Group
module Error
class Standard < StandardError; end
class AlreadyAMember < Standard
def message
"You are already a member of this group."
end
end
You can’t perform that action at this time.