This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def gen_write_handler(filename): | |
| f = open(filename, 'w') | |
| def write(buff): | |
| f.write(buff) | |
| def close(): | |
| f.close() | |
| return (write, close) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| # coding: UTF-8 | |
| from PyQt4 import QtGui, QtCore | |
| import sys | |
| class MyWidget(QtGui.QWidget): | |
| def __init__(self): | |
| super(MyWidget, self).__init__() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <qapplication.h> | |
| #include <signal.h> | |
| #include <unistd.h> | |
| using namespace std; | |
| void init_sig() | |
| { | |
| auto handler = [](int sig){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| gcc -fPIC -shared -o libnow.so now.c | |
| */ | |
| #include <time.h> | |
| #include <stdio.h> | |
| char* now() | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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> |