Skip to content

Instantly share code, notes, and snippets.

View drouillard's full-sized avatar

Douglas Drouillard drouillard

View GitHub Profile
@drouillard
drouillard / javascript-wrap-selection
Created March 9, 2011 21:03
Inserting Link in JavaScript around a selection
Fredrick Ring - http://groups.google.com/group/jquery-en/browse_thread/thread/6902e3e091ec9e4b/f8a135f66d533265?pli=1
Ok, I did it myself (+ the web). In case anyone is interested:
function wrapAsLink(url){
var textarea = document.getElementById("myTa");
var len = textarea.value.length;
var start = textarea.selectionStart;
var end = textarea.selectionEnd;
var request = require('request'),
jsdom = require("jsdom"),
sys = require('sys');
request({uri:'http://www.google.com/'}, function (error, response, body) {
console.log('Initial Response Received');
if (!error && response.statusCode == 200) {;
var doc = jsdom.jsdom(body);
@drouillard
drouillard / font-awesome-sample.css
Created March 10, 2012 08:22
Sass mixin for font-face/font-awesome
font-face("fontawesome","fontawesome-webfont")
@drouillard
drouillard / client_side_redirection.js
Created August 20, 2012 20:10
Client Side Mobile Redirection
(function() {
// General Variables and RegEx
var mobileCookie = readCookie("mw_mobile_site");
var regExUA = /ip(hone|od)|android.*(mobile)|blackberry.*applewebkit/i;
var regExDomain = /^(www(\d+)?\.)?(.*)$/;
var regExCookieDomain = /^(www(\d+)?\.)?(m.*\.)?(.*\.\w{3})$/;
// Build the top level domain
var hostname = window.location.hostname;
@drouillard
drouillard / irb_output.txt
Created August 21, 2014 04:34
Ruby Class for using Ziptastic API
Ziptastic.new.lookup "48073"
=> {"city"=>"Royal Oak", "country"=>"US", "county"=>"Oakland", "state"=>"Michigan", "state_short"=>"MI", "postal_code"=>"48073"}
Ziptastic.new.lookup "garbage"
=> {}
@drouillard
drouillard / designer.html
Last active August 29, 2015 14:05
designer
<link rel="import" href="../polymer/polymer.html">
<polymer-element name="selector-examples">
<template>
<style>
.list {
display: block;
border-top-width: 1px;
border-right-width: 1px;
@drouillard
drouillard / README
Created September 7, 2014 13:39
Nationbuilder - Handle Uppercase letters in Slugs
Nationbuilder does not accept slugs that have uppercase letters. If they are used then a the 404 page for the theme used is shown
E.G. This link will work
www.mysite.nationbuilder.com/valid
This link will **not** work
www.mysite.nationbuilder.com/Valid
@drouillard
drouillard / as.m
Last active August 29, 2015 14:13
UI Action Sheet with blocks that implements a correctly looking 'No' button. Meaning not at top of ActionSheet.
//Uses UIActionSheet+blocks
UIActionSheet *as = [[UIActionSheet alloc] initWithTitle:@"Save before leaving?"
delegate:nil
cancelButtonTitle:NSLocalizedString(@"CancelBtnText", nil)
destructiveButtonTitle:nil
otherButtonTitles:@"Yes",@"No",nil ];
as.destructiveButtonIndex = 1;
as.tapBlock = ^(UIActionSheet *actionSheet, NSInteger buttonIndex){
NSLog(@"Chose %@", [actionSheet buttonTitleAtIndex:buttonIndex]);
@drouillard
drouillard / gist:5b4583b9b3a5d9a49411
Last active September 6, 2015 16:57
require-directory with rename of dashes/hypens to camelCase
'use strict';
var requireDirectory = require('require-directory');
var renamer = function (name) {
return name.replace(/-([a-z])/g, function (m, c) {
return c.toUpperCase();
});
};
module.exports = requireDirectory(module, {rename: renamer});
@drouillard
drouillard / .bash_profile
Last active September 9, 2015 14:07
git shortcuts
alias gs='git status'
alias gd='git diff'
alias ga='git add'
alias gn="git ls-files -m | head -1"
alias gnd='gn | xargs git diff'
alias gna='gn | xargs git add; gs; gnd'
alias gnp='git push origin HEAD'
# dangerous so commented out by default
#alias gnc='gn | xargs git checkout'