Skip to content

Instantly share code, notes, and snippets.

@Glench
Glench / charCount.js
Last active December 11, 2015 06:58
Counting characters in a string for javascript
function charCount(str) {
if (!str || typeof str !== 'string') {
throw 'must provide a string';
}
var letter,
countObj = {},
alphabeticalLetters = [],
outputString = '',
letterCount;
@Glench
Glench / gui_raw_input.py
Created February 19, 2013 15:03
replace raw_input in python with GUI dialog popup text box
import easygui # easy_install easygui
some_input = easygui.enterbox(
msg="Enter some text below!",
title="Title of window",
strip=True, # will remove whitespace around whatever the user types in
default="This will show up in the box by default")
@Glench
Glench / percentChance.js
Last active December 14, 2015 17:59
calculate percentage chance, returning true or false. basically equivalent to spinning a roulette wheel and telling you if you won on that round or not.
var percentChance = function(integerPercent) {
return Math.random()*100 < integerPercent;
};
@Glench
Glench / yo_mama.md
Last active December 15, 2015 08:09
Yo Mama's Driving Directions to Her House, From the East (from the amazing book you should totally buy "A Portrait of Yo Mama as a Young Man")

Yo Mama's Driving Directions to Her House

From the East

Take I-30 eastbound to Exit 52 or 59. Go left for about forty miles. Now make a left and you should see a man sellling newspapers on the south corner. Don't be alarmed if he's not there, though; sometimes a different guy fills in for him. Continue on Comstock for 3.2 miles, and when it hits Towerview (Road or Place--I forget which, but no matter, because those two streets are /not/ parallel), make a full ninety-degree turn at my friend Patty Ann's place. (Be careful, because the sign really jumps out at you.) Continue for about eighty or ninety minutes until you see a gravel road (if you see a stop sign that is slightly lighter than the usual hue you've gone about seventy miles too far). Turn left onto the access road (it'll look like you're heading off a cliff), then drive a considerable distance forward and take I-80 West (Scranton) to Exit 65B/I-195 South (Vancouver). You idiot! Make a narrow ri

@Glench
Glench / why_you_need_functions.py
Last active December 15, 2015 12:59
A new-to-programming student asked me why you would use functions. I gave this example and I feel like this explains it well, building up abstraction from a concrete example to a more powerful, general one. For the record, you shouldn't use '+' to put strings together and you shouldn't do language translation this way. This is just to illustrate…
def say_hello_glen():
return 'hello, glen'
def say_hello(name):
return 'hello, ' + name
def greet(name, language):
if language is 'spanish':
return 'hola, ' + name
if language is 'english':
@Glench
Glench / feelinglucky.xml
Created May 30, 2013 16:22
I'm Feeling Lucky Search in Chrome's Omnibar *with suggestions*. Open up javascript console ("developer tools") in chrome and run window.external.AddSearchProvider('URL TO RAW XML')
<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
<ShortName>Google I'm Feeling Lucky</ShortName>
<Description>Google I'm Feeling Lucky Instant</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16">data:image/x-icon;base64,R0lGODlhEAAQAPfLAAATVikwdA8SnxUfgAsWpAAilholjxw4jBc7kwAlvQQ2sRMsoBUqqhMzuhY/vxw4tSgmiyM1mSUztiQ6sTE3sQ4qyxMxxRoyxiAuxR1CtBxJsBxasSJuuTFguBte0Rlf2xVc9h9W9xVjzxVr0gdj6BRh4R1o5yBcyiZbyydT1i9b2Ddb1iFY6CJg2Vpor1dzvEJu20Z0yi23QDy1REi2OUy0O1WzOVC4PU+tVUe5Sk2xQU2zRUO4UE21Ula2SmKEqWWF2HyPx2+a6X6e6Xqk1m+s78sUDs4UGdEQB9YfDdwaANEfHd0YEscjAM4mAM0qANIoD9IkGdslGswuItYgL4aP0ImP2YGZ36Opzaq2wq/S+rzX/7/e8MrS1MLO/sTb48rT8snX/83c89PZ+crq+cH1/9Dl/9Ln/93r/9fy/+Hf7P/42eDm/O7u/+T29uX2/eT2/+f4/+f5/+j/9u//8+3/9u7/9ur5/+j//+n//+v//u3//+7//e7//+////b66/T/6vX/6/f/7f/07fj/4fv/4Pj/5v/45v7/4/r+7/3/6fDw+Pfx//D/9/X/8fT/8/f/8ff/8/D///H///L8/fL///P///X7//b6/ff/+/T///b9//f///v19//w9v/09P/29v/x+f/y///z///1+v/1///2///3//j79P/58/z/8/z99/z/9v7/9P7/9vn7//v6//j9//n9//j///n//
@Glench
Glench / generate_all_font.py
Last active January 1, 2016 15:19
Generate a web page of all fonts installed on your Mac. Sample here: http://glench.com/all-fonts.html
import Cocoa
from jinja2 import Template
template = Template(u"""
<html>
<head>
<title>All Fonts Preview</title>
<style>
html, body {
margin: 0;
@Glench
Glench / format_twitter_favorites.js
Last active January 2, 2016 21:59
Format twitter favorites to make better for browsing.
$('.global-nav').remove()
$('.dashboard').remove()
$('.profile-header').remove()
$('#page-container').css({
'padding': 0,
'background': 'none'
})
$('.dogear').css({
display: 'none'
})
@Glench
Glench / all_caesar_ciphers.py
Created January 19, 2014 05:46
Get all the caesar ciphers for a given string.
# print all caesar ciphers
# python caesar.py word
import sys
for offset in range(1,26):
word = ''
for letter in sys.argv[1].lower():
num_of_letter = ord(letter)
new_num = num_of_letter + offset
>>> class X():
... pass
...
>>> x = X()
>>> x
<__main__.X instance at 0x106911908>