Skip to content

Instantly share code, notes, and snippets.

😅
err != nil

Chris Roche rodaine

😅
err != nil
Block or report user

Report or block rodaine

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
@rodaine
rodaine / boilerplate.jquery.js
Created May 15, 2012
JavaScript: jQuery Plugin Boilerplate [$(selector).method()]
View boilerplate.jquery.js
// based off Nettuts+ article by Jonathan Cutrell:
// "14 Reasons Why Nobody Used Your jQuery Plugin"
// http://goo.gl/yx8up
;(function($, window, undefined){ "use strict";
$.fn.myPlugin = function(opts) {
var defaults = {
//plugin defaults
};
@rodaine
rodaine / boilerplate.jquery.js
Created May 15, 2012
JavaScript: jQuery Plugin Boilerplate [$.method()]
View boilerplate.jquery.js
// based off Nettuts+ article by Jonathan Cutrell:
// "14 Reasons Why Nobody Used Your jQuery Plugin"
// http://goo.gl/yx8up
;(function($, window, undefined){ "use strict";
if (!$.myPlugin) $.myPlugin = function(opts) {
var defaults = {
//plugin defaults
};
@rodaine
rodaine / accordion.coffee
Last active Dec 16, 2015
Code Snippets for my blog post "Unchain HTML and JavaScript using Dependency Injection" (http://clarknikdelpowell.com/blog/untangle-html-and-javascript-using-dependency-injection/)
View accordion.coffee
$('#browsers, #web-team').on 'click', 'li', (e) ->
# get the clicked li as a jQuery object
$el = $ this
# get the whole list as a jQuery object
$delegate = $ e.delegateTarget
# the class to be toggled on the element
cls = 'active'
@rodaine
rodaine / functions.php
Created Sep 11, 2013
Gists for an upcoming blog post titled "Add A Custom Wordpress Admin Contextual Help Menu To Your Plugin Or Theme"
View functions.php
<?
add_action('init', 'cjr_register_books_cpt');
add_action('admin_menu', 'cjr_add_book_settings');
/**
* Registers the Books CPT to WordPress. Must be called in 'init' action hook.
*/
function cjr_register_books_cpt()
{
@rodaine
rodaine / Prism.markdown
Last active Dec 23, 2015
A Pen by Chris Roche.
View Prism.markdown

Prism

HTML5 Canvas based animations reminiscent of the Bezier screensaver from Windows. Essentially, it is a bunch of triangles of random color/opacity whose vertices translate independently. Tweak the values at in the config object at the top of the JS editor to affect the number of triangles, the speed of the animation, and the color pallette used.

Thanks to Paul Irish for his article on requestAnimationFrame (http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/), and Bob Nystrom for his book on Game Programming Patterns (http://gameprogrammingpatterns.com/) which inspired the loop logic for this pen.

A Pen by Chris Roche on CodePen.

License.

@rodaine
rodaine / bar.php
Last active Aug 29, 2015
How to mock a protected property on an object (assume for class Baz, Baz#foo uses Baz::$bar which needs to be mocked)
View bar.php
<?php
class Bar
{
public function getSomething()
{
return 'something';
}
}
View gist:5afef69c5f8f546ec727
### Keybase proof
I hereby claim:
* I am rodaine on github.
* I am rodaine (https://keybase.io/rodaine) on keybase.
* I have a public key whose fingerprint is 3A81 0489 67F8 B7E0 1D4C 1198 00AD F8A1 DA5A D971
To claim this, I am signing this object:
@rodaine
rodaine / bytesreader.go
Last active Jul 29, 2018
Code snippets for my blog post "Asynchronously Split an io.Reader in Go" (http://rodaine.com/2015/04/async-split-io-reader-in-golang/)
View bytesreader.go
func handleUpload(u io.Reader) (err error) {
// capture all bytes from upload
b, err := ioutil.ReadAll(u)
if err != nil {
return
}
// wrap the bytes in a ReadSeeker
r := bytes.NewReader(b)
@rodaine
rodaine / tomorrow-night-eighties-slack-theme.md
Last active Sep 13, 2019
Tomorrow Night Eighties - Slack Theme
View tomorrow-night-eighties-slack-theme.md

Based on the Tomorrow Night Eighties theme

Paste the following in the Preferences > Sidebar Theme > Custom Theme import/export field:

#2d2d2d,#393939,#6699cc,#FFFFFF,#515151,#cccccc,#99cc99,#f2777a
@rodaine
rodaine / fast.go
Last active Oct 11, 2018
Code snippets for my blog post "The X-Files: Controlling Throughput with rate.Limiter" (http://rodaine.com/2017/05/x-files-time-rate-golang/)
View fast.go
// RateLimit middleware limits the throughput to h using TickerLimiter
// configured with the provided rps and burst. The request will idle
// for the passed in wait before cancelling if there is a queue.
func RateLimit(rps, burst int, wait time.Duration, h http.HandlerFunc) http.HandlerFunc {
l, _ := TickerLimiter(rps, burst)
return func(w http.ResponseWriter, r *http.Request) {
t := time.NewTimer(wait)
select {
case <-l:
You can’t perform that action at this time.