Skip to content

Instantly share code, notes, and snippets.

View kgbu's full-sized avatar

Kazutaka Ogaki kgbu

View GitHub Profile
ghci> e: test.hs
is_prime :: (Integral a, RealFrac a, Floating a) => a -> Bool
is_prime x | x < 3 = True
| otherwise = not (any (mod0_p x) (candidates x))
mod0_p :: (Integral a) => a -> a -> Bool
mod0_p x y = (mod x y ) == 0
candidates :: (Integral t, Floating a, RealFrac a) => a -> [t]
@kgbu
kgbu / gist:773272
Created January 10, 2011 19:07
My first Android code to download to real machine.
package jp.gr.jin.OCAO;
import android.app.Activity;
import android.os.Bundle;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.widget.TextView;
import java.util.List;
@kgbu
kgbu / CookieLogin.java
Created January 14, 2011 16:57
CookieLogin.java
package jp.gr.jin.OCAO;
// based on http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientCustomContext.java
// and see Unlock Android (Japanese version) section 6.4.2 p.219
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@kgbu
kgbu / button panels
Created November 1, 2011 06:01
just a test for GraphicBuilder
import groovy.swing.SwingBuilder
import groovy.swing.j2d.GraphicsBuilder
import groovy.swing.j2d.GraphicsPanel
import java.awt.BorderLayout as BL
def gb = new GraphicsBuilder()
def shapes = [
'Arrow': gb.group {
arrow( x: 20, y: 20, width: 100, height: 60, /*rise: 0.5, depth: 0.5*/
@kgbu
kgbu / XML.stg
Created July 1, 2013 05:59
not complete, but close to work template text for code/listeners/JSON2XML_ST.java sample code of "The Definitive Guide for ANTLR4".
group XML;
empty() ::= <<
>>
object(fields) ::= <<
<fields; separator="\n">
>>
@kgbu
kgbu / purge remaing SQS messages
Created October 10, 2013 06:45
なぜ sqs.receiveMessage は1つしかメッセージを返さないか? http://stackoverflow.com/questions/9959687/retrieve-multiple-messages-from-sqs Due to the distributed nature of the queue, a weighted random set of machines is sampled on a ReceiveMessage call. That means only the messages on the sampled machines are returned. If the number of messages in the queue is smal…
// purge remaining messages
//
System.out.println("purge remaining messages");
List<Message> msgs = sqs.receiveMessage(receiveMessageRequest).getMessages();
while (msgs.size() > 0) {
Message ms = msgs.get(0);
String mDeleteH = ms.getReceiptHandle();
System.out.println("Deleting a message." + ms.getMessageId());
sqs.deleteMessage(new DeleteMessageRequest(myQueueUrl, mDeleteH));
@kgbu
kgbu / gist:afbc965d445bb5504d97
Created August 5, 2014 20:27
Display playing tune artist name and title on LCD by Raspberry Pi
#!/bin/bash
SET=/usr/sbin/i2cset
AWK=/usr/bin/awk
EXPR=/usr/bin/expr
TR=/usr/bin/tr
disp() {
playing=`/usr/bin/mpc | grep 'playing'`
if [ "$playing" != "" ]
then
@kgbu
kgbu / gist:7f0c03ea32f23d10b2de
Created August 6, 2014 02:00
Fibonatti have some variations
-module(fibo).
-export([fibnaive/1,fbuenishi/1,fblist/1, fblistuenishi/1]).
% F(0) can be 0 or 1
fibnaive(0) -> 0;
fibnaive(1) -> 1;
fibnaive(N) -> fibnaive(N - 1) + fibnaive(N - 2).
% by @kuenishi https://twitter.com/kuenishi/status/496684564488531969
@kgbu
kgbu / gist:fd79192e5b67cf1e12f8
Last active August 29, 2015 14:05
Erlang on Arduino/Sensori-Motor network
implement minimum
language (syntax, unification, functional programming)
BIF (send/receive and compiler, erts, kernel(os shall be restricted), stdlib etc.)
network layer shall be abstracted.
how to extend memory size to accomodate Erlang proccess?
http://arms22.blog91.fc2.com/blog-entry-403.html (Serial SRAM 32KB)
os shall boot from external serial ROM (SPI)
@kgbu
kgbu / SSD4LinuxSVR.md
Last active August 29, 2015 14:05
SSD for Linux server

referred sites

buyers voice

http://shop.tsukumo.co.jp/goods/0405786629016/201405000000000/ is recommended by https://twitter.com/htaira/status/504523337725272067