This file contains hidden or 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 time | |
class TimedOperation(object): | |
"Describes a single operation with timing information" | |
__slots__ = ('description', '_cpustart', '_cpuend', '_wallstart', '_wallend') | |
def __init__(self, description): | |
self.description = description | |
self._cpustart = time.clock() | |
self._cpuend = None |
This file contains hidden or 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
# a heavy int is one where the average of the digits is greater than 7 | |
# eg: 8678 is heavy because (8 + 6 + 7 + 8) / 4 = 7.25 | |
# 8677 is not heavy because ( 8 + 6 + 7 + 7) / 4 = 7 | |
def is_heavy(my_number, heaviness=7): | |
# map each digit to a float and divide by the length | |
digits = str(my_number) | |
return sum(map(float, digits)) / len(digits) > heaviness |
This file contains hidden or 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
serve_file(Response, File) -> | |
case file:open(File, [raw, binary]) of | |
{ok, IoDevice} -> | |
%% Set ChunkSize to an optimal value | |
ChunkSize = 1024, | |
Stream = iodevice_stream(IoDevice, ChunkSize), | |
Response1 = setelement(4, Response, Stream), | |
file:close(IoDevice), | |
Response1; | |
_ -> |
This file contains hidden or 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
-spec(read_input_string/2 :: (integer(), ewgi_context()) -> string()). | |
read_input_string(Size, Ctx) when is_integer(Size) -> | |
R = read_input(Ctx), | |
Iol = R(read_input_string_cb([]), Size), | |
Bin = iolist_to_binary(Iol), | |
binary_to_list(Bin). | |
read_input_string_cb(Acc) -> | |
F = fun(eof) -> |
This file contains hidden or 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
%% ===================================================================== | |
%% Redistribution and use in source and binary forms, with or without | |
%% modification, are permitted provided that the following conditions | |
%% are met: | |
%% | |
%% 1. Redistributions of source code must retain the above | |
%% copyright notice, this list of conditions and the following | |
%% disclaimer. | |
%% | |
%% 2. Redistributions in binary form must reproduce the above |
This file contains hidden or 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 python | |
def baz(f): | |
def wrapper(*args, **kwargs): | |
print 'Calling wrapper...' | |
return f(*args, **kwargs) | |
return wrapper | |
class Foo(object): | |
def __init__(self, i): |
This file contains hidden or 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
#!/bin/bash | |
FOO="Hello, world" | |
FOO_ARGS=" -kernel bar \"${FOO}\" " | |
exec erl -noshell ${FOO_ARGS} -eval 'io:format("~p~n", [application:get_env(kernel, bar)]), halt(0).' | |
#exec erl -noshell -kernel bar '"Hello, world"' -eval 'io:format("~p~n", [application:get_env(kernel, bar)]), halt(0).' |
This file contains hidden or 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
;; This buffer is for notes you don't want to save, and for Lisp evaluation. | |
;; If you want to create a file, visit that file with C-x C-f, | |
;; then enter the text in that file's own buffer. | |
This file contains hidden or 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(test_re2). | |
-compile(export_all). | |
-type word() :: list(). | |
-type phi() :: 'phi'. | |
-type empty() :: 'empty'. | |
-record(letter, {l :: char()}). | |
-record(choice, {left, right}). | |
-record(seq, {left, right}). |
This file contains hidden or 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
--2009-02-16 13:51:19-- (try: 2) http://www.google.co.uk/ | |
Connecting to www.google.co.uk|208.69.34.231|:80... failed: Connection refused. | |
Connecting to www.google.co.uk|208.69.34.230|:80... failed: Connection refused. | |
Resolving www.google.co.uk... 208.69.34.231, 208.69.34.230 | |
Connecting to www.google.co.uk|208.69.34.231|:80... failed: Connection refused. | |
Connecting to www.google.co.uk|208.69.34.230|:80... failed: Connection refused. |