Skip to content

Instantly share code, notes, and snippets.

View slightair's full-sized avatar
🍄
Hello

Tomohiro Moro slightair

🍄
Hello
View GitHub Profile
@slightair
slightair / ca1d.clj
Created April 15, 2012 17:15
one-dimensional cellular automaton
(def trials 32)
(def rule 90)
(def initial-state (concat (repeat 32 0) '(1) (repeat 32 0)))
(defn show-cells [cells]
(println (apply str (map #(cond (= % 0) " "
(= % 1) "*") cells))))
(defn neighbors [state]
(concat
@slightair
slightair / CoderwallAPIClientTest.m
Created April 27, 2012 13:58
CoderwallAPIClientTest uses NLTHTTPStubServer
//
// CoderwallAPIClientTest.m
// CoderwallAPIClientExample
//
// Created by slightair on 12/04/23.
// Copyright (c) 2012 slightair. All rights reserved.
//
#define kStubServerPort 12345
@slightair
slightair / gist:2509557
Created April 27, 2012 14:07
sample CoderwallAPIClient
[[CoderwallAPIClient sharedClient] profileForUsername:@"slightair"
completion:^(CoderwallUserProfile *profile){
// success
}
failure:^(NSError *error){
// failure
}];
val Width = 129
val Height = 48
val MaxTrial = 200
def recurrence(pxn: Double, pyn: Double, a: Double, b: Double, trial:Int):Int = trial match {
case MaxTrial => MaxTrial
case _ => {
val xn = pxn * pxn - pyn * pyn + a
val yn = 2 * pxn * pyn + b
package cc.clv
object InverseFizzBuzz extends App {
case object FizzBuzz
case object Fizz
case object Buzz
def fizzbuzzSequence(limit: Int) = Range(1, limit).collect {
case x if x % 15 == 0 => (x, FizzBuzz)
case x if x % 3 == 0 => (x, Fizz)
@slightair
slightair / gist:2949580
Created June 18, 2012 17:35
sample for kue issue #110
var kue = require('kue');
var jobs = kue.createQueue();
jobs.process('job', function(job, done){
var progressMax = 3;
var next = function(i){
console.log("job-%d-%s [%d/%d] #%d", job.data.id, job.data.title, i, progressMax, job.id);
job.progress(i, progressMax);
if (i == progressMax) {
require "faraday"
conn = Faraday::Connection.new(url: 'https://api.parse.com') do |builder|
builder.request :url_encoded
builder.adapter :net_http
end
response = conn.get do |request|
request.url '/1/classes/Foo'
request.headers = {
@slightair
slightair / gist:4192942
Created December 3, 2012 05:26
ひろし
>> puts "ひろし".unpack("b*")[0].scan(/../).map{|x|%w(ヴ ィ ム …)[x.to_i(2)]}.join("")
…ヴィ…ムヴヴィィヴ…ィ…ヴィ…ィヴヴィム…ヴィ…ヴィ…ムヴヴィ…ムムィ
=> nil
>> puts ["…ヴィ…ムヴヴィィヴ…ィ…ヴィ…ィヴヴィム…ヴィ…ヴィ…ムヴヴィ…ムムィ".scan(/ヴ|ィ|ム|…/).map{|c|%w(ヴ ィ ム …).index(c)}.map{|i|"%02b"%i}.join("")].pack("b*")
ひろし
=> nil
@slightair
slightair / gist:4608690
Created January 23, 2013 16:04
dispatch_semaphore test?
#import <Foundation/Foundation.h>
#import <dispatch/dispatch.h>
int main (int argc, char const *argv[])
{
int i;
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_semaphore_t semaphore = dispatch_semaphore_create(1);
for(i = 0; i < 10; i++) {
@slightair
slightair / gist:5748273
Created June 10, 2013 12:09
Time#to_f
[1] pry(main)> RUBY_VERSION
=> "2.0.0"
[2] pry(main)> require 'active_support/time'
=> true
[3] pry(main)> Time.new(2013, 4, 1).end_of_day
=> 2013-04-01 23:59:59 +0900
[4] pry(main)> Time.new(2013, 4, 1).end_of_day.to_f
=> 1364828400.0
[5] pry(main)> Time.at(1364828400.0)
=> 2013-04-02 00:00:00 +0900