Skip to content

Instantly share code, notes, and snippets.

@chomy
chomy / pycurl_test.py
Last active December 27, 2015 20:49
test of pycurl using closure
def gen_write_handler(filename):
f = open(filename, 'w')
def write(buff):
f.write(buff)
def close():
f.close()
return (write, close)
#!/usr/bin/python
a = [True, True, False, True]
reduce(lambda x,y: x and y, a, True) #-> False
a[2] = True
reduce(lambda x,y: x and y, a, True) #-> True
b = [None, None, 1, None]
reduce(lambda x,y: x and (y==None), b, True) #-> False
b[2] = None
import numpy as np
import scipy.optimize
func = lambda x,a,b,c: a + b*x + c*x*x
x,y = np.loadtxt('fit.dat', unpack=True)
print scipy.optimize.curve_fit(func, x, y)
import sys
import PyQt4.QtCore as QtCore
import PyQt4.QtGui as QtGui
class painter(QtGui.QWidget):
def __init__(self, parent=None):
super(painter,self).__init__(parent)
self.resize(400,300)
@chomy
chomy / pyqt4_custom_widget.py
Created December 19, 2013 07:17
Sample code of custom widget using PyQt
#!/usr/bin/python
# coding: UTF-8
from PyQt4 import QtGui, QtCore
import sys
class MyWidget(QtGui.QWidget):
def __init__(self):
super(MyWidget, self).__init__()
@chomy
chomy / iota.lisp
Created February 6, 2014 06:21
function iota in common lisp
(defun iota (m &optional (n 1) (step 1))
(defun iter (m n lst)
(cond ((> n m) (reverse lst))
(t (iter m (+ n step) (cons n lst)))))
(iter m n nil))
@chomy
chomy / qt_daemon.cxx
Created March 8, 2014 08:06
template of daemon with Qt4
#include <qapplication.h>
#include <signal.h>
#include <unistd.h>
using namespace std;
void init_sig()
{
auto handler = [](int sig){
@chomy
chomy / now.c
Created April 26, 2014 11:27
FFI test on CLISP
/*
gcc -fPIC -shared -o libnow.so now.c
*/
#include <time.h>
#include <stdio.h>
char* now()
{
@chomy
chomy / sicp_chapt3.1.scm
Last active August 29, 2015 14:06
SICP Chapter 3.1
;; 3.1
(define (make-accumulator sum)
(lambda (n) (set! sum (+ sum n))))
;; 3.2
(define (make-monitored f)
(let ((count 0))
(lambda (param)
(cond ((eq? 'how-many-calls? param) count)
((eq? 'reset param) (set! count 0))
@chomy
chomy / httpclient.c
Created October 2, 2014 07:27
HTTP Client in C
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netdb.h>
#include <errno.h>
#define GNU_SOURCE
#include <signal.h>