Skip to content

Instantly share code, notes, and snippets.

View tkojitu's full-sized avatar

aka. bakaiku or @gdgdiler tkojitu

View GitHub Profile
@tkojitu
tkojitu / PlaySquareWave.rb
Created December 24, 2011 14:51
play square wave from JRuby.
include Java
java_import javax.sound.sampled.AudioFormat
java_import javax.sound.sampled.DataLine
java_import javax.sound.sampled.SourceDataLine
java_import javax.sound.sampled.AudioSystem
SAMPLE_RATE = 44100
audio_format = AudioFormat.new(SAMPLE_RATE, 8, 1, true, true)
info = DataLine::Info.new(SourceDataLine.java_class, audio_format)
@tkojitu
tkojitu / NomaoiController.java
Created January 5, 2012 12:14
Connect MidiIn to Synthezier.
package nomaoi;
import java.awt.Dimension;
import javax.sound.midi.*;
import javax.swing.*;
public class NomaoiController implements Runnable {
MidiDevice midiIn;
Synthesizer synth;
@tkojitu
tkojitu / Metronome.java
Created February 6, 2012 12:35
Metronome with javax.sound.midi.Sequencer
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.midi.*;
public class Metronome implements MetaEventListener {
private Sequencer sequencer;
private int bpm;
public void start(int bpm) {
try {
@tkojitu
tkojitu / metronome.rb
Created February 8, 2012 11:31
metronome in jruby
include Java
import javax.sound.midi.MetaEventListener
import javax.sound.midi.MidiEvent
import javax.sound.midi.MidiSystem
import javax.sound.midi.Sequence
import javax.sound.midi.ShortMessage
class Metronome
include MetaEventListener
@tkojitu
tkojitu / HowToUseStructInArduino.cxx
Created February 19, 2012 01:46
How to use struct in Arduino
struct Control {
int pin;
};
void ctrlPinMode(void* control, int mode) {
Control* ctrl = (Control*)control;
pinMode(ctrl->pin, mode);
}
int ctrlDigitalRead(void* control) {
@tkojitu
tkojitu / HowToUseClassInArduino.cxx
Created February 19, 2012 01:57
How to use class in Arduino
class Control {
public:
int pin;
Control(int pin) : pin(pin) {}
~Control() {}
void pinMode(int mode) {
::pinMode(pin, mode);
}
@tkojitu
tkojitu / SerialSwitch.java
Created February 27, 2012 14:43
send command to arduino via serial (usb) port.
import gnu.io.CommPortIdentifier;
import gnu.io.PortInUseException;
import gnu.io.SerialPort;
import gnu.io.UnsupportedCommOperationException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
include Java
import java.awt.Rectangle
import java.awt.geom.Ellipse2D
import java.awt.geom.Line2D
import java.awt.geom.Point2D
import java.awt.geom.Rectangle2D
import java.lang.Math
import javax.swing.JFrame
@tkojitu
tkojitu / rb.rb
Created May 7, 2012 03:55
okwave.jp/qa/q7454381.html
class MyRecord
def initialize(line)
@alpha, @number, @value = line.split
end
attr_reader :alpha, :number, :value
end
def print_alpha_number(records)
num_keys = records.map{|rec| rec.number}.uniq.sort
alpha_keys = records.map{|rec| rec.alpha}.uniq.sort
@tkojitu
tkojitu / rect.html
Created June 10, 2012 04:12
Draw and rotate a rect in JavaScript Canvas.
<html>
<head>
<script type="text/javascript">
var app = {
rect: {
x: 100,
y: 100,
w: 100,
h: 100,
a: 0