Skip to content

Instantly share code, notes, and snippets.

# @file: pyh.py
# @purpose: a HTML tag generator
# @author: Emmanuel Turlay <turlay@cern.ch>
__doc__ = """The pyh.py module is the core of the PyH package. PyH lets you
generate HTML tags from within your python code.
See http://code.google.com/p/pyh/ for documentation.
"""
__author__ = "Emmanuel Turlay <turlay@cern.ch>"
__version__ = '$Revision$'
@fcamel
fcamel / gist:c013c6ca4279ba1c937f
Created June 20, 2015 07:49
benchmark dictionary get/set for node.js, CPython2, pypy
$ cat h.js
n = 100000000;
s = {};
key = "abc";
s[key] = 0;
for (i = 0; i < n; i++) {
s[key] += 1;
}
console.log(s[key]);
$ time node h.js
@fcamel
fcamel / gist:beef85e5c3b9ab78507b
Last active August 29, 2015 14:23
Benchmark CPython2, PyPy, Node.js
$ cat h.py
n = 100000;
d = {};
for _ in xrange(1000):
for k in xrange(n):
if k not in d:
d[k] = k * 2
else:
d[k] += 1
print d[n - 1]
The character used to test UCS-2 error: 𝌆
@fcamel
fcamel / l10n.php
Last active August 29, 2015 14:26
PHP and JavaScript Localization
<?php
$g_default_lang = "en";
$g_messages = array();
function get_target_language() {
global $g_default_lang;
if (isset($_GET['lang'])) {
return $_GET['lang'];
}
@fcamel
fcamel / test_memory_by_reading_file.js
Created August 10, 2015 06:31
Test ndoe.js memory usage
/*
usage: nodejs test_memory_by_reading_file.js LARGE_FILE
It looks no memory limit for the process with node.js v0.10.38,
but single project cannot use more than ~2G.
*/
var sleep = require('sleep');
var fs = require('fs');
var bs = [];
for (var i = 0; i < 10; i++) {
qsort :: Ord a => [a] -> [a]
qsort [] = []
qsort (x:xs) = qsort small ++ [x] ++ qsort big
where small = [x'| x' <- xs, x' < x]
big = [x'| x' <- xs, x' >= x]
* Levels of tests
o unit test
o integration test
o system test
o acceptance test
* Why test? (acceptance test / system test)
o verify correctness: bugs always exist (but we can keep them small and easier to solve)
o save manually verification time
* Why unit test?
o help find root of bugs (save debugging time)
import Test.QuickCheck
import Data.List
--
-- aux functions for verifications
--
isOrdered :: Ord a => [a] -> Bool
isOrdered [] = True
isOrdered [x] = True
isOrdered (x:x2:xs) = x <= x2 && isOrdered (x2:xs)
--
-- wc.hs: word count
--
-- Given a file name in the first command line argument,
-- print WORD: COUNT for each WORD per line.
-- The output is ordred by COUNT.
--
import System
import Data.List