Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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 / 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
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 / 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]);
@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 / Checkbox-slider.markdown
Created July 16, 2014 02:17
A Pen by Ian McNally.
@ianmcnally
ianmcnally / react-from-angular.md
Last active August 29, 2015 14:16
Coming to React from Angular

Coming to React from Angular

My friends started using it, Stride clients started asking for it, and it's been getting serious buzz on the internet. So I realized it was time for me to learn React.

I've been an Angular guy for the past couple years, and I've gotten pretty good at it. I've seen its nooks and crannies, and I've grown fond of it.

But, like I said, it was hard to ignore React.

It's fast, it's light, it's new and shiny. So I dug in. I recently released an app, Farely, which I'd written in Angular. (Note: I didn't use directives like I should have.) I thought it'd be the perfect opportunity to try out React, since the app could be composed of components. It also wouldn't need anything React doesn't offer, like routing or complex data modeling.

@ianmcnally
ianmcnally / gist:c986117b81f60bc107d3
Last active August 29, 2015 14:18
My week in angular, js, testing

A week's small victories: Angular, Equality and Testing

Our work weeks are made up of victories both big and small. What really gets me writing is the small. The a-ha! moments. The high fives (internal ones count too). The green builds. The git pushes.

I spent my week creating dynamic forms and lists in Angular. I made them, fought with them, tested them, and came out the other side in one piece. Here's my story:

Writing and testing custom form validators

Custom form validators are a powerful feature in Angular.