This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
filetype plugin indent on | |
syntax on | |
set autoindent | |
set expandtab | |
set shiftwidth=4 | |
set tabstop=4 | |
set smarttab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
Name, DoB, (current_date - DoB) as Age | |
FROM | |
People | |
WHERE | |
Name = 'John Smith' | |
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let person = filter (\x -> name x == "John Smith") people | |
age dob = getCurrentTime >>= return . (\now -> (diffDays now dob) `div` 365) . utctDay | |
in | |
[name person, dob person, age (dob person)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// BAD: | |
List<PersonEntity> pes = someFetcherFunction.findByAgeGreaterThan(18); | |
if (pes.contains(currentPE)) { return "Hello, sir/madam."; } | |
else { return "This method is for adults only!"; } | |
// GOOD: | |
static Integer LEGAL_ADULTHOOD_AGE = 18; // in class PersonEntity | |
//... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<PersonEntity> attendees = conference.getAttendees(); | |
Collections.sort(new Comparator<PersonEntity> { | |
@Override | |
public int sort(PersonEntity person1, PersonEntity person2) { | |
Date person1ArrivalDate = person1.getArrivalDate(), | |
person2ArrivalDate = person2.getArrivalDate(); | |
if (person1ArrivalDate == null) person1ArrivalDate = DEFAULT_ARRIVAL_DATE; | |
if (person2ArrivalDate == null) person2ArrivalDate = DEFAULT_ARRIVAL_DATE; | |
int comparisonByArrivalDateResult = person1ArrivalDate.compareTo(person2ArrivalDate); | |
if (comparisonByArrivalDateResult == 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<PersonEntity> attendees = conference.getAttendees(); | |
Collections.sort(new Comparator<PersonEntity> { | |
@Override | |
public int sort(PersonEntity person1, PersonEntity person2) { | |
final int BOTH_ARE_EQUAL = 0; | |
int comparisonByArrivalDateResult = this.compareByArrivalDate(person1, person2); | |
if (comparisonByArrivalDateResult == BOTH_ARE_EQUAL) { | |
int comparisonByTicketTierResult = this.compareByTicketTier(person1, person2); | |
if (comparisonByTicketTierResult == BOTH_ARE_EQUAL) { | |
return this.compareByLastName(person1, person2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List | |
import Text.Regex | |
encloseField :: String -> String | |
encloseField field | |
| "," `isInfixOf` field = "\"" ++ (escapeField field) ++ "\"" | |
| otherwise = escapeField field | |
escapeField :: String -> String | |
escapeField field |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var repl = require('repl'); | |
var __ = require('underscore')._; | |
var files = {}; | |
var jsonFiles = process.argv.slice(2); | |
jsonFiles.forEach(function(val) { | |
files[val] = JSON.parse(fs.readFileSync(val)); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Assumption: arrayOfElements is an array of DOM nodes created from a template or otherwise. */ | |
/* Don't do this! This reflows the DOM a *lot* */ | |
var targetNode = document.getElementById('target'); | |
var appendToTargetNode = targetNode.appendChild.bind(targetNode); | |
arrayOfElements.forEach(appendToTargetNode); | |
/* Instead, use a DocumentFragment */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Again, the assumption: arrayOfElements is an array of DOM nodes created from a template or otherwise. */ | |
/* We can set our targetNode to "display:none", change it, and then reset it, making it into a poor man's DocumentFragment */ | |
var targetNode = document.getElementById('target'); | |
var previousDisplayValue = targetNode.style.display; | |
targetNode.style.display="none"; /* 1 reflow */ | |
var appendToNode = targetNode.appendChild.bind(targetNode); | |
arrayOfElements.forEach(appendtoTargetNode); /* 0 reflows */ |
OlderNewer