Skip to content

Instantly share code, notes, and snippets.

@tom-lpsd
tom-lpsd / GC.java
Last active September 16, 2016 17:20
java -verbose:gc -XX:+PrintGCDetails -XX:+PrintPromotionFailure -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+PrintGCDateStamps -Xmx1g -Xms1g -Xmn100m -XX:CMSInitiatingOccupancyFraction=99 GC 2000000
import java.util.Random;
public class GC {
static class Foo {
byte[] raw;
public Foo(int n) {
raw = new byte[n];
}
}
@tom-lpsd
tom-lpsd / foo.c
Created October 6, 2012 13:06
compicate type decl
#include <stdio.h>
char foo()
{
return 'x';
}
char bar()
{
return 'y';
@tom-lpsd
tom-lpsd / gist:1115336
Created July 30, 2011 08:44
combinations.hs
combinations :: [a] -> [[a]]
combinations [] = [[]]
combinations (x:xs) = concat [[t, (x:t)] | t <- combinations xs]
@tom-lpsd
tom-lpsd / palindrome.hs
Created July 13, 2011 15:26
don't use reverse
isPalindrome :: String -> Bool
isPalindrome str = isPalindrome' str [] (len `div` 2)
where
len = length str
isPalindrome' [] _ _ = True
isPalindrome' xs ys 0 = if len `mod` 2 == 0 then xs == ys else (tail xs) == ys
isPalindrome' (x:xs) ys n = isPalindrome' xs (x:ys) (n - 1)
@tom-lpsd
tom-lpsd / hello_daemon_plugin.c
Created April 13, 2011 05:30
MySQL daemon plugin sample.
#include <stdio.h>
#include <mysql_version.h>
#include <mysql/plugin.h>
struct st_mysql_daemon hello_daemon_plugin =
{ MYSQL_DAEMON_INTERFACE_VERSION };
static FILE *fp;
int hello_daemon_plugin_init(void *p)
@tom-lpsd
tom-lpsd / sicp-2.11.scm
Created January 8, 2011 02:33
answer for sicp question 2.11
(define (make-interval a b) (cons a b))
(define (upper-bound r) (max (car r) (cdr r)))
(define (lower-bound r) (min (car r) (cdr r)))
(define (mul-interval x y)
(define (cross-zero? a b)
(and (<= a 0) (>= b 0)))
(let ((a (lower-bound x))
use strict;
use warnings;
use Data::Dump qw(dump);
use Regexp::Assemble;
my $regexp1 = Regexp::Assemble->new;
$regexp1->track;
$regexp1->add('foo.*');
$regexp1->add('bar.*');
package Vector;
use strict;
use warnings;
use List::Util qw(sum);
use List::MoreUtils qw(pairwise);
our ($a, $b);
sub new {
my ($class, $data) = @_;
use strict;
use warnings;
use Benchmark qw/cmpthese/;
sub ret_by_value {
my $n = shift;
my @seq = (0..$n);
return @seq;
}
package Foo;
use 5.010;
use strict;
use warnings;
sub TIESCALAR {
my $class = shift;
bless \(my $init = "initial value"), $class;
}