Skip to content

Instantly share code, notes, and snippets.

View kyontan's full-sized avatar
♨️

kyontan kyontan

♨️
View GitHub Profile
@kyontan
kyontan / slice_bit_string.c
Last active August 29, 2015 14:05
Slice bit string
#include<stdio.h>
#include<stdbool.h>
void print_bit_string(unsigned char n) {
for(int i=7; 0<=i; i--) {
printf("%d", (n >> i) & 1);
}
}
unsigned char slice_bit_string(unsigned char data[], int data_len, char slice_unit, int idx) {
@kyontan
kyontan / buttons.css
Created August 24, 2014 12:59
CSS3 Buttons
input.button, button.button {
height: 34px;
cursor: pointer;
-webkit-appearance: none;
}
.button {
background-color: #EEE;
display: inline-block;
vertical-align: middle;
@kyontan
kyontan / gist:5ac417f87a9be340c2c2
Created March 25, 2015 09:26
AudioQueueを使ってPCMを再生
NSData *recordedPcm;
AVAudioPlayer *player;
AudioQueueRef audioQueue;
AudioQueueBufferRef audioQueueBuffers;
// Queue/Buffer への追加は playPCM での1回しかしないため、コールバックでは何もしない (必要があればここで追加)
static void AQOutputCallback(void *userData, AudioQueueRef audioQueueRef, AudioQueueBufferRef audioQueueBufferRef) {
return;
}
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Test
{
public static void main (String[] args) throws java.lang.Exception
@kyontan
kyontan / rpn.rb
Last active August 29, 2015 14:26
逆ポーランド記法で計算するやつ
#!/usr/bin/env ruby
class Array
alias_method :top, :last
end
def eval_rpn(stack)
commands = {
"+": ->x, y { x + y },
"-": ->x, y { x - y },
@kyontan
kyontan / Helper.cpp
Last active October 31, 2015 02:40
Arduino で ADXL345 (加速度センサー) と OSL641501 (8x8 ドットマトリックスLED) を使った教材用のラッパーライブラリ
#include <Wire.h> // I2C用
#include <ADXL345.h> // 加速度センサ用
#include <TimerOne.h> //timer1 //timer0はdelay、timer2はtoneで使われてる(´・ω・`)
// #include "dtmtdatas.h"
#include "Helper.h"
// val の値を min と max の値に収まるようにする
// val < min :=> min
// min <= val <= max :=> val
#!/usr/bin/env ruby
require 'capybara'
# require 'capybara/poltergeist'
require "selenium-webdriver"
Capybara.current_driver = :selenium
url = "http://qrlogic.pwn.seccon.jp:10080/game/"
@kyontan
kyontan / custom_logger.rb
Created December 9, 2015 16:22
STDOUT にも同時に吐いてくれる Logger
class Logger
alias_method :add_old, :add
remove_method :add, :log
def method_missing(method_name, *args, &block)
if /^log|add$/ === method_name
puts "#{(args[1] && args[1] + ": ") || ""}#{args[2]}"
self.send(:add_old, *args, &block)
end
end
@kyontan
kyontan / StatusManager.h
Last active December 22, 2015 12:23
Too Simple StatusManager in Objective-C (CC0)
//
// StatusManager.h
//
// Created by kyontan on 2015/12/22.
// Licensed under CC0
//
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSInteger, Status) {
@kyontan
kyontan / gist:c2d049e52f82e08b3b08
Created March 4, 2016 09:22
画像に隙間を作るやつ
def get_dim(f)
return 2 if f.include?(?2)
return 3 if f.include?(?3)
return 1
end
def gravity(g)
return "west" if g == "l"
return "east"