Skip to content

Instantly share code, notes, and snippets.

@ianmcnally
ianmcnally / Checkbox-slider.markdown
Created July 16, 2014 02:17
A Pen by Ian McNally.
@ianmcnally
ianmcnally / word_pair_counts.coffee
Created July 2, 2014 23:50
A function to retrieve the most frequent word pair in a string
#
# Write a function `wordPair` that for a
# given a string, returns the most frequent word pair (word, space, word)
# E.g., 'I want to be a part of it New York, New York' -> 'New York'
#
wordPair = (str) ->
getWordPairCounts = (str) ->
words = str.replace(/[^a-zA-Z\s]/g, '').split ' '
pairCounts = {}
@ianmcnally
ianmcnally / balanced_parenthesis.js
Last active August 29, 2015 14:03
Balanced parenthesis
function isBalanced(string) {
var closers = {
'{' : '}',
'(' : ')',
'[' : ']'
}
var stack = [];
for (var i = 0, l = string.length; i < l; i++) {
if (closers[string[i]]) {
stack.push(string[i]);
fizzbuzz = ->
for n in [1..100]
fizz = if n % 3 is 0 then 'fizz' else ''
buzz = if n % 5 is 0 then 'buzz' else ''
output = fizz + buzz or n
console.log output
@ianmcnally
ianmcnally / sublime_as_mergetool.txt
Created June 30, 2014 17:31
Sublime text as merge tool
git config --global mergetool.sublime.cmd "subl -w \$MERGED"
git config --global mergetool.sublime.trustExitCode false
git config --global merge.tool sublime
Usage:
git mergetool -y
@ianmcnally
ianmcnally / charles_instructions.txt
Created June 30, 2014 17:31
Charles proxy instructions for Localhost
Configuring Charles to proxy, so you can test localhost on a virtual machine.
1. In Charles proxy settings, set a port, i.e., 8889.
2. In your VM, modify the local area settings.
1. In IE, go to Settings > Connections > LAN Settings
2. Under proxy server, select Use a proxy server.
3. Under proxy server Address, use your machine's IP.
4. Under proxy server Port, use the Charles proxy port, i.e., 8889.
3. Turn on proxying in Charles.
@ianmcnally
ianmcnally / update_input_on_blur.coffee
Created June 30, 2014 17:30
Update input on blur - Angular
# Only update <input> elements with bound angular models <input ng-model="my model"> on 'blur' event.
# Tweaked from a variety of places.
app.directive 'updateOnBlur', ->
require : 'ngModel'
link : (scope, element, attributes, ngModelController) ->
element.unbind 'input'
element.bind 'blur', ->
scope.$apply ->
ngModelController.$setViewValue element.val()
@ianmcnally
ianmcnally / longest_palindrome.rb
Created June 30, 2014 17:28
Longest palindrome
def longest_palindrome str
palindromes = []
str.split('').each.with_index do |c, i|
0.upto i do |j|
# get all substrings up to the current letter
chunk = str[j..i]
reverse_chunk = chunk.reverse
# check if they're a palindrome
palindromes << chunk if chunk == reverse_chunk
end