Skip to content

Instantly share code, notes, and snippets.

@rgo
rgo / gist:74026
Created March 4, 2009 21:45
Awesome truncate
# Awesome truncate
# From: http://daniel.collectiveidea.com/blog/2007/7/10/a-prettier-truncate-helper
#
# First regex truncates to the length, plus the rest of that word, if any.
# Second regex removes any trailing whitespace or punctuation (except ;).
# Unlike the regular truncate method, this avoids the problem with cutting
# in the middle of an entity ex.: truncate("this & that",9) => "this &am..."
# though it will not be the exact length.
def awesome_truncate(text, length = 30, truncate_string = "...")
return if text.nil?
@raggi
raggi / alias_task.rake
Created November 12, 2009 15:11
A helper to alias a task in rake
def alias_task(name, old_name)
t = Rake::Task[old_name]
desc t.full_comment if t.full_comment
task name, *t.arg_names do |_, args|
# values_at is broken on Rake::TaskArguments
args = t.arg_names.map { |a| args[a] }
t.invoke(args)
end
end
@lindenb
lindenb / bin.c
Created June 8, 2011 06:44
Adds a UCSC 'bin' column
/**
* Author: Pierre Lindenbaum PhD (original source is from Jim Kent: http://genomewiki.ucsc.edu/index.php/Bin_indexing_system
* Motivation: Adds a UCSC 'bin' column see http://biostar.stackexchange.com/questions/8943/get-rs-number-based-on-position
* Compilation: gcc bin.c
* Execute: echo -e "chr1\t10326\t10327\trs112750067" | ./a.out
* History: updated so it prints all the bins in a at any depth
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@tetu1225
tetu1225 / app.rb
Created July 18, 2011 06:00
Sinatraで画像ファイルをアップロードして表示する
require 'sinatra'
require 'haml'
# 静的コンテンツ参照のためのパス設定
set :public, File.dirname(__FILE__) + '/public'
# アップロード
get '/' do
haml :index
@misshie
misshie / viterbi.rb
Created September 18, 2011 12:05
A Ruby implementation of the Viterbi algorithm based on the hidden Markov model (HMM)
# A Ruby implementation of
# the Viterbi algorithm based on the hidden Markov model (HMM)
#
# An original Python code: a Wikipedia page "Viterbi algorithm" at
# http://en.wikipedia.org/wiki/Viterbi_algorithm
#
# Author: MISHIMA, Hiroyuki
#
require 'pp'
@ktym
ktym / sparql.rb
Last active June 20, 2024 20:45
SPARQL query interface
#!/usr/bin/env ruby
require "rubygems"
require "net/http"
require "uri"
require "cgi"
require "json" # gem install json
class SPARQL
@tcnksm
tcnksm / docker_cheat.md
Last active August 5, 2021 03:59 — forked from wsargent/docker_cheat.md
Docker 虎の巻

Docker 虎の巻

何故Dockerを使うべきか

Why Should I Care (For Developers)

"Dockerが面白いのはシンプルな環境に隔離性と再現性をもたらしてくれることだ.ランタイムの環境を一度作れば、パッケージにして別のマシンでも再利用することできる.さらに,すべてはホスト内の隔離された環境で行われる(VMのように).最も素晴らしい点は,シンプルかつ高速であることだ."

@tomonari-masada
tomonari-masada / maximal_substrings.c
Created February 28, 2017 08:47
extracting maximal substrings from UTF8 Japanese strings
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#define SEPCHAR '_'
#define MAXLEN 32
#define BUFFSIZE 1000000
#define TOKENLEN 8