Skip to content

Instantly share code, notes, and snippets.

View pguillory's full-sized avatar

Preston Guillory pguillory

  • Pinterest
  • San Francisco
View GitHub Profile
@pguillory
pguillory / output.txt
Last active June 14, 2016 16:51
Built-in macros expanding to invalid code
case(:condition) do
x when x in [false, nil] ->
nil
_ ->
:ok
end
case(:condition) do
x when Enum.member?([false, nil], x) ->
nil
_ ->
@pguillory
pguillory / game.ex
Last active February 25, 2016 07:29
defmodule Game do
# Client
def start do
spawn &Game.play/0
end
def move(pid, request) do
send(pid, {:request, self, request})
receive do
I.
THE LIFE AND DEATH OF SCYLD.
{The famous race of Spear-Danes.}
Lo! the Spear-Danes' glory through splendid achievements
The folk-kings' former fame we have heard of,
How princes displayed then their prowess-in-battle.
@pguillory
pguillory / text.md
Last active March 19, 2017 23:39
Internet Explorer quirk: HTML entities in URLs

Try going into your browser console and typing:

window.location = 'http://causes.com/?a=true&not_a=false'

Now look at your address bar. What you see depends on which browser you're using.

Chrome, Firefox: http://www.causes.com/?a=true&not_a=false

.nav-item {
&:nth-child(1) {
@media {min-width: 200px) {
display: none;
}
}
&:nth-child(2) {
@media {min-width: 250px) {
display: none;
@pguillory
pguillory / classify_version.js
Created October 19, 2012 19:04
Classify vs Closures
Causes.SomeClass = Causes.classify({
init : function() {
this.value = 0;
$('#something').on('click', this.handlerFunc.bind(this));
},
handlerFunc : function(event) {
event.preventDefault();
this.value += 5;
},
package main
type SomeCollection struct {
members []int
}
func (this *SomeCollection) Append(i int) {
this.members = append(this.members, i)
}
# Returns parsed CSS
def extract_css
css = @dom.css('style, link[rel=stylesheet]').collect do |node|
next unless /^$|screen|all/ === node['media'].to_s
node.remove
if node.name == 'style'
node.content
else
uri = %r{^https?://} === node['href'] ? node['href'] : File.join(@stylesheets_path, node['href'].sub(/\?.+$/,''))
@pguillory
pguillory / gist:839545
Created February 22, 2011 22:16
Sync vs. Async
// Synchronous form - 6 lines
function f() {
a()
b()
c()
d()
}
// Asynchronous form - 12 lines
function f(callback) {
// foo.js
console.log('foo');
require('bar').print();
//bar.js
exports.print = function() {
console.log('bar');
}