Skip to content

Instantly share code, notes, and snippets.

// Sieve of Eratosthenes
def calc_primes( nums:List[Int] ):List[Int] = {
nums match {
case x::xs =>
val nums_dash = for( i <- xs if i % x != 0 ) yield i
println( Runtime.getRuntime.totalMemory/1024/1024 )
x :: calc_primes( nums_dash )
case _ => Nil
}
}
@bongole
bongole / tmux.rb
Created July 14, 2011 08:18
brew tmux-1.5 pbcopy fix patch
require 'formula'
class Tmux < Formula
url 'http://sourceforge.net/projects/tmux/files/tmux/tmux-1.5/tmux-1.5.tar.gz'
md5 '3d4b683572af34e83bc8b183a8285263'
homepage 'http://tmux.sourceforge.net'
depends_on 'libevent'
def patches
@bongole
bongole / gulpfile.js
Last active August 29, 2015 14:04
gulp + react + browserify
var gulp = require('gulp');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var reactify = require('reactify');
gulp.task('build', function(){
var bundler = browserify('./app/app.js');
bundler.transform(reactify, {"es6": true});
return bundler.bundle()
.pipe(source("app.js"))
@bongole
bongole / compile-android.sh
Last active March 24, 2022 21:13
compile jq for android
#!/bin/sh
autoreconf -fi >/dev/null 2>&1
NDK_ROOT=/usr/local/opt/android-ndk
curl http://www.geocities.jp/kosako3/oniguruma/archive/onig-5.9.5.tar.gz | tar xz
cd onig-5.9.5
# So, we need to remake the configure scripts so that the arm64 architecture
@bongole
bongole / build.gradle
Last active September 4, 2017 04:27
gradle build file for JavaCPP
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 9
targetSdkVersion 21
versionCode 1
@bongole
bongole / init.js
Created April 27, 2015 07:03
atom init.js for non ascii markdown-toc
var marked = require(atom.packages.resourcePath + "/node_modules/marked");
marked.Renderer.prototype.heading = function(text, level, raw) {
return '<h'
+ level
+ ' id="'
+ this.options.headerPrefix
+ raw.toLowerCase().replace(/[\s]+/g, '-')
+ '">'
+ text
+ '</h'
defmodule EctoTest.Repo do
use Ecto.Repo, otp_app: :ecto_test
import Ecto.Query
def find_or_create_by(queryable, attrs) do
q = Enum.reduce(attrs, queryable, fn
{field, val}, query ->
query |> where([x], field(x, ^field) == ^val)
_, query -> query
atomic-1.1.99.gem: $CFLAGS += " -march=native"
atomic-1.1.99-java.gem: $CFLAGS += " -march=native"
bit-twiddle-0.0.5.gem:$CFLAGS << ' -Wall -Werror -O3 -march=native -mtune=native -std=c99 '
chruby-0.3.gem:CFLAGS := "-O3 -march=native"
cityhash-0.8.1.gem:%w{g O3 Wall march=native}.each do |flag|
concurrent-ruby-0.7.2-x64-mingw32.gem: $CFLAGS += " -march=native"
concurrent-ruby-0.7.2-x86_64-linux.gem: $CFLAGS += " -march=native"
concurrent-ruby-0.7.2-x86-linux.gem: $CFLAGS += " -march=native"
concurrent-ruby-0.7.2-x86-mingw32.gem: $CFLAGS += " -march=native"
concurrent-ruby-0.7.2-x86-solaris-2.11.gem: $CFLAGS += " -march=native"
HOST_IP=$(curl -s 169.254.169.254/latest/meta-data/local-ipv4)
TASKS_JSON=$(curl -s $HOST_IP:51678/v1/tasks)
CONTAINER_ID=$(cat /proc/self/cgroup | grep "cpu:/" | sed 's/.*cpu:\/docker\///g')
TASK_ID=$(echo $TASKS_JSON|jq -r ".Tasks[] | select(.Containers[].DockerId == \"$CONTAINER_ID\") | .Arn"|sed 's/.*task\///')
TASK_FAMILY=$(echo $TASKS_JSON|jq -r ".Tasks[] | select(.Containers[].DockerId == \"$CONTAINER_ID\") | .Family")
@bongole
bongole / date_parse.rs
Created February 16, 2017 10:16
nomで日付のパーステスト
#[macro_use]
extern crate nom;
use nom::*;
fn take_digits_n(input: &[u8], n: u8) -> IResult<&[u8],&[u8]> {
verify!(input, take!(n), |chars: &[u8]| chars.iter().all(|c: &u8| is_digit(*c)) )
}
named!(take_4_digits, apply!(take_digits_n, 4));
named!(take_1_or_2_digits, alt_complete!( apply!(take_digits_n, 2) | apply!(take_digits_n, 1)) );