Skip to content

Instantly share code, notes, and snippets.

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

Weerasak Chongnguluam iporsut

🏠
Working from home
View GitHub Profile
@iporsut
iporsut / device_server.erl
Created January 31, 2011 15:19
simulate electronic board that communicate by socket
-module(device_server).
-compile(export_all).
start() ->
{ok, Listen} = gen_tcp:listen(51, [binary,
{reuseaddr, true},
{active, true}]),
{ok, Socket} = gen_tcp:accept(Listen),
gen_tcp:close(Listen),
@iporsut
iporsut / gist:838300
Created February 22, 2011 06:36
Edit distance
int findMin(int d1, int d2, int d3)
{
/*
* return min of d1, d2 and d3.
*/
if(d1 < d2 && d1 < d3)
return d1;
else if(d1 < d3)
return d2;
else if(d2 < d3)
@iporsut
iporsut / gist:853365
Created March 3, 2011 19:47
Cromartie Mountain
#include <stdio.h>
typedef struct _mountain{
int s;
int h;
} MOUNTAIN;
void sort_mountain(MOUNTAIN *m,int c) {
int i,j;
MOUNTAIN tmp;
@iporsut
iporsut / gist:860153
Created March 8, 2011 11:11
dare to hide
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX_ROW 64
#define MAX_COLUMN 64
#define ctoi(C) (C - '0')
typedef struct _room_pos {
int m;
@iporsut
iporsut / gist:860200
Created March 8, 2011 12:08
cromartie key
#include <stdio.h>
#include <string.h>
#define mid(A,B,C) ((A >= B && A <= C) || (A >= C && A <= B)?A:(((B >= A && B <= C) || (B >= C && B <= A))?B:C))
int main(int argc, char *argv[])
{
char lock_up[80];
char lock_down[80];
char key[80];
int lock_max,key_max;
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#define MAX 21
typedef struct _list {
int n;
struct _list *next;
@iporsut
iporsut / gist:881555
Created March 22, 2011 16:51
Crawler class
<?php
class Crawler
{
private $_group_id = '';
private $graph_api = 'https://graph.facebook.com';
public function __construct($group_id) {
$this->_group_id = $group_id;
}
public function getGroup() {
@iporsut
iporsut / gist:999307
Created May 30, 2011 18:51
Convert Base Number
-module(xbase).
-export([count/2])
count(Base,Max) ->
count(($0+Base),"0",lists:reverse(integer_to_list(Max))).
count(_,Current,Current) ->
io:format("~s~n",[lists:reverse(Current)]),
ok;
count(Base,Current,Max) ->
io:format("~s~n",[lists:reverse(Current)]),
@iporsut
iporsut / gist:1012940
Created June 7, 2011 19:22
Digit Solve
public class Solve {
public static void main(String [] args) {
int T = 0,O = 0,G = 0,D = 0;
int temp;
for (int oo = 3; oo <= 9; oo++) {
if ( ((((4*oo)+(40*oo)) % 100) / 10) == oo) {
temp = ((4*oo)+(40*oo));
for (int tt = 1; tt <= 9; tt++) {
if ( (((((400*tt) + temp)) / 100) % 10) == oo) {
int result = (400*tt) + temp;
@iporsut
iporsut / echo.go
Created June 8, 2011 11:46
echo by go
package main
import ("fmt"; "os")
func main() {
for i := 1; i < len(os.Args); i++ {
if i > 1 {
fmt.Print(" ")
}
fmt.Print(os.Args[i])
}