Skip to content

Instantly share code, notes, and snippets.

@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++) {
@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'];
}
The character used to test UCS-2 error: 𝌆
@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]
@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
# @file: pyh.py
# @purpose: a HTML tag generator
# @author: Emmanuel Turlay <[email protected]>
__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 <[email protected]>"
__version__ = '$Revision$'
#include <iostream>
#include <set>
enum Type {
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z
};
bool isOkayBySwitch(Type type) {
switch (type) {
case A:
.file "switch_cases_check.cpp"
.text
.p2align 4,,15
.globl _Z14isOkayBySwitch4Type
.type _Z14isOkayBySwitch4Type, @function
_Z14isOkayBySwitch4Type:
.LFB1206:
.cfi_startproc
cmpl $24, %edi
ja .L4
#include <iostream>
#include <set>
enum Type {
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z
};
bool isOkayBySwitch(Type type) {
switch (type) {
case A:
import gdb
# Ref. http://stackoverflow.com/a/14698568/278456
v = gdb.selected_frame().read_var('LOCAL_VARIABLE_NAME')
for k in v.type.target():
try:
print k, v[k]
except Exception, e:
pass