Skip to content

Instantly share code, notes, and snippets.

View smly's full-sized avatar
👁️‍🗨️

smly smly

👁️‍🗨️
View GitHub Profile
@smly
smly / gist:1299656
Created October 19, 2011 20:59
redis-2.4.1 / 4 x Intel(R) Xeon(R) CPU X3430 @ 2.40GHz / Intel SSDSA2M160 / MEM: 4GB
testredis06/1$ redis-cli flushall
OK
testredis06/1$ redis-load clients 100 requests 10000000 datasize 32 keyspace 10000000 set 100
testredis06/0$ redis-cli info | grep -E "(db0:keys|used_memory_human|mem_fragmentation_ratio)"
used_memory_human:836.31M
mem_fragmentation_ratio:1.02
db0:keys=6321117,expires=0
@smly
smly / ShortestDistance.scala
Created July 30, 2011 10:58
using bagel to compute shortest distance
package spark.bagel.examples
import spark._
import spark.SparkContext._
import scala.math.min
import spark.bagel._
import spark.bagel.Bagel._
@smly
smly / pfi2011.c
Created July 29, 2011 02:34
majority
#include <stdio.h>
int main()
{
char curr, next, ans;
unsigned int cnt;
for (curr = getchar();;curr = next) {
if ((next = getchar()) == EOF || next == '\n') break;
if (next == curr) {
if (cnt == 0) ans = next;
@smly
smly / ternary_like.sml
Created July 17, 2011 04:28
ternary operator like expression
datatype 'a ternarylikeop = TrueExpression of 'a | FalseExpression
fun op ? (true, y) = TrueExpression y
| op ? (_, y) = FalseExpression
infix 6 ?;
fun op :- (TrueExpression x, _) = x
| op :- (FalseExpression, y) = y
infix 6 :-;
@smly
smly / oops_ternary_operator.sml
Created July 17, 2011 04:27
want to pass the false-expression to define a ternary operation
$ sml
Standard ML of New Jersey v110.72 [built: Sun May 22 00:51:36 2011]
- fun op -: (x,y,z) = x + y * z;
val -: = fn : int * int * int -> int
- infix 6 -:;
- 3 -: 2;
stdIn:5.1-5.7 Error: operator and operand don't agree [tycon mismatch]
operator domain: int * int * int
operand: int * int
in expression:
@smly
smly / shm_counter.pl
Created July 16, 2011 10:53
IPC using shared memory
#!/usr/bin/perl -w
use strict;
use warnings;
use IPC::Shareable;
my $glue = 'access_counter';
my %options = (
create => 'yes',
exclusive => 0,
mode => 0644,
destroy => 0,
@smly
smly / dgim_method.rb
Created June 10, 2011 10:43
Datar-Gionis-Indyk-Motwani method
#!/usr/bin/env ruby
# encoding: utf-8
# using ruby 1.9.2p180
# Author: Kohei Ozaki (@smly)
# demo of DGIM method
# ref:
# Mayur Datar, Aristides Gionis, Piotr Indyk, and Rajeev Motwani
# "Maintaining stream statistics over sliding windows",
>>> x= np.matrix([[2,3],[4,5],[5,6],[6,7]]).T
>>> x
matrix([[2, 4, 5, 6],
[3, 5, 6, 7]])
>>> u,s,vh = np.linalg.svd(x)
>>> u
matrix([[-0.63626513, -0.77147047],
[-0.77147047, 0.63626513]])
>>> s
array([ 14.13594166, 0.41851331])
#include <iostream>
#include <fstream>
#include <vector>
#include <sstream>
#include <gtest/gtest.h>
#include "lp.hpp"
#include "testing/utils.hpp"
namespace gmll {
@smly
smly / lp.sh
Created July 25, 2010 08:57
use matlab code written by Xiaojin Zhu
#!/bin/sh
# Usage: lp.sh -w W.txt -l L.txt -p result.csv
# * requirement
# http://pages.cs.wisc.edu/~jerryzhu/pub/harmonic_function.m
# and matlab.
MATLAB=matlab
HELP="$0 -w <weight_matrix> -l <label_matrix> -p <predict_matrix>"