Skip to content

Instantly share code, notes, and snippets.

View cskevint's full-sized avatar

Kevin Trotter cskevint

View GitHub Profile
@cskevint
cskevint / github_userscript.js
Last active July 12, 2019 03:19
UserScript that enhances GitHub.com repo links.
// ==UserScript==
// @name Add GitHub Repo Links
// @namespace http://cskevint.github.io/
// @version 0.1.1
// @description Add some useful links to the header area of a GitHub repo.
// @match http*://github.com/*
// @copyright 2013, Kevin Trotter
// ==/UserScript==
$(function(){
@cskevint
cskevint / pluckNested.js
Last active December 21, 2015 15:09
_.pluckNested is a better implementation of _.pluck from underscore.js
// Convenience version of a common use case of `map`: fetching a property.
// The property can be nested using "." notation.
// _.pluckNested([{a:{z:1}},{a:{z:2}}],"a.z") ==> [1, 2]
_.pluckNested = function(obj, key) {
var objKey = key.split('.');
return _.map(obj, function(o) {
var value = o, item;
_.each(objKey, function(key) {
if(_.isObject(value[key])) {
value = value[key];
@cskevint
cskevint / titleize.js
Created June 19, 2013 19:54
Titleize a sentence in JavaScript
function titleize(sentence) {
if(!sentence.split) return sentence;
var _titleizeWord = function(string) {
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
},
result = [];
sentence.split(" ").forEach(function(w) {
result.push(_titleizeWord(w));
});
return result.join(" ");
@cskevint
cskevint / hash_binding_example.rb
Created June 1, 2013 05:40
A HashBinding class takes a simple ruby hash and uses a class's binding to create the context for the rendering of an ERB template.
require 'erb'
class HashBinding
def initialize(hash)
hash.each do |key, value|
singleton_class.send(:define_method, key) { value }
end
end
def context