Skip to content

Instantly share code, notes, and snippets.

@atton
atton / gist:2300703
Created April 4, 2012 12:08
regexp "foobar"
# -*- coding: utf-8 -*-
# fooが頭に無いbarをファイルに出力する
reg = /(?<!foo)bar/
array = ["foo","bar","baz"]
file_name = "./hoge.txt"
f = File.open file_name,"a+"
@atton
atton / gist:2300727
Created April 4, 2012 12:14
double regexp "foobar"
# -*- coding: utf-8 -*-
# fooが頭に無いbarをファイルに出力する 2
array = ["foo","bar","baz"]
file_name = "./hoge.txt"
f = File.open file_name,"a+"
array.each do |head|
@atton
atton / gist:2300884
Created April 4, 2012 12:56
regexp "foobar" v2
# -*- coding: utf-8 -*-
# fooが頭に無いbarをファイルに出力する 1.2
array = ["foo","bar","baz","hoge"]
reg = /(?<!foo)bar/
file_name = "./hoge.txt"
f = File.open file_name,"a+"
@atton
atton / gist:2300896
Created April 4, 2012 12:57
double regexp "foobar" v2
# -*- coding: utf-8 -*-
# fooが頭に無いbarをファイルに出力する 2.2
array = ["foo","bar","baz","hoge"]
file_name = "./hoge.txt"
f = File.open file_name,"a+"
array.each do |head|
@atton
atton / gist:2365464
Created April 12, 2012 07:38
shell script option test
#!/bin/sh
# shell script option test
a=0
b=0
while getopts ab opt
do
case ${opt} in
a)
@atton
atton / gist:2576895
Created May 2, 2012 14:27
prime check
def prime? num
return 0 if num == 1
(num-1).downto(2) do |n|
return 0 if num.modulo(n) == 0
end
return 1
end
(define (hoge a b c)
(define (square x) (* x x))
(define (minimum x y) (if (< x y) x y))
(-
(+ (square a) (square b) (square c))
(square (minimum a (minimum b c)))))
@atton
atton / 1_10.scm
Created May 12, 2012 05:31
sicp 1.10
(define (A x y)
(cond ((= y 0) 0)
((= x 0) (* 2 y))
((= y 1) 2)
(else (A (- x 1)
(A x (- y 1))))))
(A 1 10)
(A 2 4)
(A 3 3)
@atton
atton / bot.rb
Created June 7, 2012 10:23
ruby bot
# -*- coding: utf-8 -*-
require 'twitter'
Twitter.configure do |config|
config.consumer_key = gets.chomp
config.consumer_secret = gets.chomp
config.oauth_token = gets.chomp
config.oauth_token_secret = gets.chomp
end
@atton
atton / gist:3069690
Created July 8, 2012 06:44
increment-test(gcc4.2.1)
#include <stdio.h>
int test(void){
int n = 2;
n = ++n;
printf("%d\n",n); // 3
return 0;
}
int hoge(void){