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
// Initial version w/ explicit types: | |
Dictionary<string, string> users = db.Users.Where(u => u.Account.Id == accountID).ToDictionary<User, string, string>(u => u.Id.ToString(), u => u.Login.Username); | |
// Without explicit type info. | |
var users = db.Users.Where(u => u.Account.Id == accountID).ToDictionary(u => u.Id.ToString(), u => u.Login.Username); |
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
$(document).ready(function() { | |
$('body').empty(); | |
document.title = "REDDIT IS A WASTE OF TIME"; | |
}); |
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
-module(larray). | |
-include_lib("eunit/include/eunit.hrl"). | |
-export([intersection/2]). | |
intersection(ListA, ListB) -> | |
Numbers = lists:foldl( fun(N, Ranking) -> dict:update_counter(N, 1, Ranking) end , dict:new(), ListA ++ ListB), | |
lists:usort([Unique || Unique <- dict:fetch_keys(Numbers), dict:fetch(Unique, Numbers) > 1]). | |
%% helper functions to create big lists of random integers | |
large_random_array(N, MaxValue) -> |
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
-module(larray). | |
-include_lib("eunit/include/eunit.hrl"). | |
-export([intersection/2]). | |
intersection(ListA, ListB) -> | |
[X || X <- ListA, lists:member(X, ListB)]. |
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
fields = re.findall("(\"[^\"\r]+\"|[^,\r]+)", row) |
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
words = [] | |
for line in sys.stdin.readlines(): | |
for word in line.split(): | |
words.append(word) | |
# VS. | |
words = [word for line in sys.stdin.readlines() for word in line.split()] |
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
// Two tips from Brian Kernighan: | |
// 1. Say what you mean, simply and directly. | |
// 14. Use symbolic constants for magic numbers. (Applies to chars and strings too.) | |
// | |
namespace System | |
{ | |
public static class SentenceParser | |
{ | |
protected char BLANK = ' '; |
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
def logged_in? | |
!! DB.execute("SELECT id FROM sessions WHERE session_key=? LIMIT 1", params[:session_key]) | |
end |
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
def group?(current, last) | |
current.created_at - last.created_at < 1.minute | |
end | |
recent_statuses.inject([]) { |results, status| | |
next results << [status] if results.empty? # Can't compare first item. | |
results << group?(status, results.last.last) ? stat : [stat] | |
} |
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
#!/usr/bin/env perl | |
use strict; | |
use constant StartY => 123; | |
use constant BP => 0; | |
use constant PATTERN_BUFFER => 0x7F800; | |
sub register | |
{ | |
my $register = shift; | |