Skip to content

Instantly share code, notes, and snippets.

@chomy
chomy / gist:3499421
Created August 28, 2012 15:57
factrial in OCaml
let fact n
let rec fact_ite n t =
if n = 0 then t
else fact_ite (n-1) (n*t);;
in
fact_ite n 1;;
@chomy
chomy / serial_test.c
Created September 28, 2012 08:10
serial port test for linux
#include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
/*
* 'open_port()' - Open serial port 1.
*
@chomy
chomy / jps2text.rb
Created December 5, 2012 02:23
Convert JPS format to ascii text.
#!/usr/bin/ruby
require "rexml/parsers/streamparser"
require "rexml/parsers/baseparser"
require "rexml/streamlistener"
class JPS2TextListener
include REXML::StreamListener
def initialize
@chomy
chomy / jps2asc.py
Created December 7, 2012 07:47
Convert JPS to ESRI Grid format
#!/usr/bin/python
# -*- coding: utf-8 -*-
import xml.parsers.expat
import codecs
import sys
nextaction = None
current = None
@chomy
chomy / daytime.lisp
Created February 8, 2013 11:55
daytime client written in Common Lisp.
(asdf:load-system :usocket)
(defun daytime-client (host)
(usocket:with-client-socket (socket stream host 13)
(read-line stream nil nil)))
(asdf:load-system :usocket)
(load "/usr/share/common-lisp/source/usocket/usocket.lisp")
(defun tcp-handler (stream)
(multiple-value-bind (sec min hr date mon yr day daylight zone)
(get-decoded-time)
(format stream "~D-~D-~D ~D:~D:~D~%" yr mon date hr min sec)))
(usocket:socket-server "127.0.0.1" 9090 #'tcp-handler)
@chomy
chomy / gl.js
Last active December 13, 2015 21:39
Grid Locator calculation code
/*
gl.js
Grid Locator Calcuration Library
version 1.0
Copyright (C) 2013 Keisuke Nakao (chome@argv.org)
This library is free software: you can redistribute is and/or modify
it under the terms of the GNU General Public Licenses as published by
@chomy
chomy / daytime_server_1
Created August 25, 2013 04:06
Very very simple daytime server. This code is for education
#!/usr/bin/python
import socket
from datetime import datetime
HOST=''
PORT=8014
sock = socket.socket(socket.AF_INET|socket.AF_INET6, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind((HOST, PORT))
@chomy
chomy / lambda_fizzbuzz.py
Last active December 21, 2015 16:09
FizzBuzz code use only lambda.
#!/usr/bin/python
buzz = lambda x:[(lambda _x: "" if _x%5 else "Buzz")(x), x]
fizz = lambda x: (x[0] if x[0]=='Buzz' else x[1]) if x[1]%3 else "Fizz" + x[0]
for i in range(1,100):
print fizz(buzz(i))
@chomy
chomy / sample_gnuplot.py
Last active December 25, 2015 14:19
Gnuplot.py test
import Gnuplot
data = Gnuplot.Data( ((1,1),(2,2),(3,3)), with_='lp', title='test plot')
g = Gnuplot.Gnuplot()
# Plot on display
g.plot(data)
# Hardcopy
g.hardcopy('plot.ps', 'postscript')