Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
#
# Ruby 1.9以降必須。Array#combinationとか便利だし
# Ken Nishimura 2010/4/5
#
# (方針)
#
# 単騎待ちとそれ以外を分けて考える。再帰で3つずつ区切って幅優先探索。順
# 子、コーツ以外はその場で探索打ち切り。もう少し重複を刈り取れるけど、
@knsmr
knsmr / wctweet.rb
Created January 2, 2011 22:53
Analyze Tweets and count the numbers of each letters used
# -*- coding: utf-8 -*-
require 'twitter'
class MyTweets
def initialize(name)
@name = name
@c = Twitter::Client.new
@tweets = []
end
# Huffman coding
#
class Node
attr_accessor :val, :weight, :left, :right
def initialize(val = "", weight = 0)
@val, @weight = val, weight
end
class BoardFactory
def self.create(text_or_state)
case text_or_state
when String
text = text_or_state
state = []
text.each_line do |l|
next if l =~ /^$/
state << l.chomp.split(//)
end
require 'fileutils'
File.open("./numeric.c", "r") do |klass|
File.open("./numeric.tmp", "w") do |tmpfile|
while line = klass.gets
tmpfile.write line
if line =~ /fix_to_s\(int argc, VALUE \*argv, VALUE x\)/
2.times {tmpfile.write klass.readline}
tmpfile.write <<PATCH
int val;
@knsmr
knsmr / gist:1216339
Created September 14, 2011 11:19
magic matrix solver
#
# Magic matrix solver
# Ken Nishimura 2011/9/14
#
# Solver.new(Matrix.new((1..9))).solve yeilds:
#
# |8|1|6|
# |3|5|7|
# |4|9|2|
#
@knsmr
knsmr / gist:1218261
Created September 15, 2011 00:56
get number of likes using graph api
require 'open-uri'
require 'json'
def facebook_api
@facebook_api ||= "https://graph.facebook.com/?ids="
end
def retrieve_numbe_of_likes(url)
resp = open(facebook_api+url).read
JSON.parse(resp)[url]["shares"]
@knsmr
knsmr / gist:1354474
Created November 10, 2011 09:10 — forked from hay/gist:1351230
Enterprisify your Java Class Names!
<!doctype html>
<html>
<head>
<title></title>
<style>
body {
background: white;
text-align: center;
padding: 20px;
font-family: Georgia, serif;
$(function(){
var canvas = $("#dragon")[0],
ctx = canvas.getContext("2d");
$.extend(ctx, {
strokeStyle: "rgb(255, 127, 0)",
lineWidth: 1
});
var Turtle = function (x, y, vector) {
$related_tags = {}
qestion_tags = [
%w(ruby rails ide),
%w(rails db),
%w(ruby rails db mysql),
%w(mysql sql),
%w(rails mysql),
%w(ruby rails postgres)
]