Skip to content

Instantly share code, notes, and snippets.

View hidenba's full-sized avatar
🏠
Working from home

hidekuni KAJITA hidenba

🏠
Working from home
View GitHub Profile
@hidenba
hidenba / analogin.c
Created July 18, 2016 22:24
ArduinoのanalogINをBLEで使う
#include <CurieBLE.h>
const int ledPin = 13; // set ledPin to use on-board LED
BLEPeripheral blePeripheral; // create peripheral instance
BLEService alcoholService("29B10000-E8F2-537E-4F6C-D104768A1214"); // create service
BLEShortCharacteristic alcoholChar("29B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite | BLENotify);
const int termLedPin = 13;
const int alcoholSensorPin = 0;
#include <CurieBLE.h>
const int ledPin = 13; // set ledPin to use on-board LED
BLEPeripheral blePeripheral; // create peripheral instance
BLEService alcoholService("29B10000-E8F2-537E-4F6C-D104768A1214"); // create service
BLEShortCharacteristic alcoholChar("29B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite | BLENotify);
const int termLedPin = 13;
const int alcoholSensorPin = 0;
const int pin_a = 10;
const int pin_b = 12;
const int pin_c = 9;
const int pin_d = 4;
const int pin_e = 5;
const int pin_f = 8;
const int pin_g = 11;
const int pin_dp = 13;
const int dig1 = 2;
const int dig2 = 3;
public class Game {
public static Player matchUp(Player player1, Player player2) {
String left = player1.getStrategy(player2.getStrategySize());
String right = player2.getStrategy(player1.getStrategySize());
for(int i=0; i < left.length(); i++) {
char left_hand = left.charAt(i);
char right_hand = right.charAt(i);
if( left_hand == 'R' && right_hand =='S') {
return player1;
class Tournament
def self.start(players)
if players.length == 2
game(players, []).first
else
left_count = players.length / 2
right_count = players.length - left_count
right = players.pop(right_count)
left = players
class Point
attr_accessor :point, :color
def initialize(point, color)
@point = point
@color = color
end
def toggle
@color = color == 'R' ? 'W' : 'R'
class WebkitToPng
def self.create(urls, options={})
urls.each do |url|
puts "convert #{url} to #{options[:dir]}"
url.sub!('//', "//#{options[:auth]}@") if options[:auth]
op = "-F -D #{options[:dir]} -o #{url.split('/').last}"
op += " --user-agent='#{user_agent}'" if options[:mobile]
exec(url, op)
end
@hidenba
hidenba / gist:4576468
Created January 20, 2013 03:15
OSXでのメモリステータス
ruby -e 'puts `vm_stat`.gsub!(/([0-9]*)\.$/){ "#{($1.to_i * 4096 / 1000000.0).round(2)}M" }'
@hoges =Kaminari::paginate_array(Hoge.find_by_sql('select * from hoges limit 25'), total_count: 37,).page(1).per(25)
paginate @hoges
# changedの振る舞い
t = Event.new
param = {:year=>2000, :month=>'', :day=>nil}
t.attributes = param
t.changed? #=> true
t.year_changed? #=> true
t.month_changed? #=> false
t.day_changed? #=> false
t.changes #=> {"year"=>[nil, 2000]}