Skip to content

Instantly share code, notes, and snippets.

#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
static const unordered_map<int, int> mapA{};
int funcA(int key) {
auto f = mapA.find(key);
// A ZeroCopyOutputStream which appends bytes to a string.
// It has much a more favorable performance profile than StringOutputStream
// outside of Google since STLStringResizeUninitialized() is un-optimized.
class LIBPROTOBUF_EXPORT StringOutputStream2 : public ZeroCopyOutputStream {
public:
explicit StringOutputStream2();
~StringOutputStream2();
// implements ZeroCopyOutputStream ---------------------------------
bool Next(void** data, int* size);
use strict;
use warnings 'all';
use Tie::File;
use Fcntl 'O_RDWR';
my $file = "to-sort.txt";
tie my @nums, 'Tie::File', $file
, mode => O_RDWR
, recsep => ', '
, memory => 20_000_000 # max 20 MB read buffer
@na-ka-na
na-ka-na / iiit.clj
Created December 8, 2013 21:21
Search for higher level topological patterns in the secondary structure of RNA.
(ns iiit
(:import
[java.io Writer File OutputStream FileOutputStream BufferedReader BufferedWriter FileReader FileWriter]
[java.util Collections])
(:use
[clojure stacktrace]
[clojure.set :only (union intersection difference)]
[clojure.contrib repl-utils trace pprint str-utils (io :only (spit append-spit make-parents delete-file))]
[clojure.contrib.shell :only (sh)]))
; MPI kind macros
(defmacro BLOCK_LOW [i p n] `(int (/ (* ~i ~n) ~p)))
(defmacro BLOCK_HIGH [i p n] `(- (BLOCK_LOW (+ 1 ~i) ~p ~n) 1))
(defmacro BLOCK_SIZE [i p n] `(- (BLOCK_LOW (+ 1 ~i) ~p ~n) (BLOCK_LOW ~i ~p ~n)))
(defmacro BLOCK_ONWER [j p n] `(int (/ (- (* (inc ~j) ~p) 1) ~n)))
(defn partition-work
[p coll]
(let [s (seq coll)
n (count s)]
@na-ka-na
na-ka-na / MemoizeTest.java
Created May 14, 2012 00:19
Memoize usage
import java.util.Random;
import java.util.concurrent.*;
import lombok.Memoize;
public class MemoizeTest {
@Memoize
public static int test(final int k){
System.out.println("test " + k);
return k+2;
@na-ka-na
na-ka-na / Delomboked.java
Created May 13, 2012 23:24
@lombok.Memoize
/*
@lombok.Memoize
final Number test(int a, Double b) {
return null;
}
*/
class Test{
@java.lang.SuppressWarnings("all")
@na-ka-na
na-ka-na / GroupPlusLayout.java
Created January 8, 2012 13:28
JGraph group + auto layout
package com.mxgraph.examples.swing;
import javax.swing.JFrame;
import com.mxgraph.layout.mxGraphLayout;
import com.mxgraph.layout.mxOrganicLayout;
import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph;
@SuppressWarnings("serial")
(defn- print-map [m print-one w]
(#'clojure.core/print-sequential
"{"
(fn [e ^java.io.Writer w]
(do (print-one (key e) w) (.append w " ") (print-one (val e) w)))
", "
"}"
(seq m) w))
@na-ka-na
na-ka-na / ExprEval.java
Created April 12, 2011 15:11
Power of Reflection + Enum + Comparable to generate a simple expression evaluator
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
class AProp implements Comparable<AProp>{
private final int a;
public AProp(int a){
this.a = a;
}
@Override
public int compareTo(AProp other) {