Skip to content

Instantly share code, notes, and snippets.

View matsumotius's full-sized avatar

Matsumoto Akihiro matsumotius

View GitHub Profile
@matsumotius
matsumotius / 8queen.rb
Created January 8, 2012 05:07
8queen
def eight_queen(n = 8, m = 8)
run(n, m, [])
end
def run(kinds, len, a)
return unless can_set_queen?(a)
if len == 0 then
puts a.join(',')
else
kinds.times { |i|
@matsumotius
matsumotius / timer.js
Created January 25, 2012 00:20
timer
var timer = function(sec, internal, finished) {
var limit = parseInt(sec);
var count = 0;
var counter = setInterval(function(){
count++;
if(count < limit) {
if(typeof internal == "function") internal(count, limit);
} else {
if(typeof finished == "function") finished(count, limit);
clearInterval(counter);
@matsumotius
matsumotius / gyapin_test.rb
Created January 29, 2012 15:19
gyapin test
def gyapin(image, source, alt, title)
host = "http://pinterest.com/pin/create/bookmarklet/"
url = host + "?media=" + image +
"&url=" + source +
"&alt=" + alt +
"&title=" + title + "&is_video=false"
system "google-chrome \"#{url}\""
end
gyapin("http://cache.gyazo.com/99ba9338b392dc5750492cfc1f0c4f94.png",
@matsumotius
matsumotius / app.js
Created March 1, 2012 22:35
get session from socket.io
var express = require('express');
var parse_cookie = require('connect').utils.parseCookie;
var MemoryStore = express.session.MemoryStore;
var session_store = new MemoryStore();
var app = module.exports = express.createServer();
app.configure(function(){
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.methodOverride());
@matsumotius
matsumotius / plugin.js
Created March 28, 2012 09:52
jQuery plugin sample
(function($) {
/* extend jQuery */
$.fn.yellow = function(options) {
$(this).css('background-color', 'yellow');
return "plugin test";
};
})(jQuery);
@matsumotius
matsumotius / ht.js
Created June 4, 2012 18:27
huffman tree
var Node = function(value, left, right, word){
this.value = value;
this.left = left;
this.right = right;
this.word = word;
};
var HuffmanTree = function(wordcount){
this.list = [];
for (var word in wordcount) {
this.list.push(new Node(wordcount[word], null, null, word));
import scala.collection.mutable.HashMap
class HuffmanTree(str: String) {
abstract class Node {
val count: Int
}
case class Leaf(str:String, count:Int) extends Node
case class Branch(left: Node, right: Node) extends Node {
val count = left.count + right.count
}
@matsumotius
matsumotius / focus.js
Created September 2, 2012 23:34
set focus color
(function($){
$.fn.colorFocus = function(color, trigger){
var defaultColor = $(this).css('background-color');
var hasTrigger = (typeof trigger == 'function');
$(this).mouseover(function(e){
if (hasTrigger && false == trigger(this)) return;
$(this).css('background-color', color);
});
apply plugin: 'android'
apply plugin: 'android-apt'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 9
targetSdkVersion 14