Skip to content

Instantly share code, notes, and snippets.

View Liudx1985's full-sized avatar
😇
All repos are moved to https://gitee.com/liudx1985/ Permanently!

Liudx Liudx1985

😇
All repos are moved to https://gitee.com/liudx1985/ Permanently!
View GitHub Profile
from io import StringIO
import sys
old_stdout = sys.stdout
sys.stdout = mystdout = StringIO()
# blah blah lots of code ...
print("fuck me god")
sys.stdout = old_stdout
@Liudx1985
Liudx1985 / mpi-start.txt
Created October 28, 2014 08:29
Boost.MPI
MPI实践起来真是有点困难,因为好多外国网站上不去,只能自己摸索:
1.setup mpich2
mpiexec -remove to remove account for each computer node
mpiexec -register to add account for each computer 'node'
mpiexec -validate to validate the account
Notice ,you must create a account(username/password all same) for all nodes on windows.
2.build boost.mpi
修改boost_1_47_0\tools\build\v2\tools\mpi.jam文件,修改的地方如下:
@Liudx1985
Liudx1985 / _embed.py
Created October 9, 2014 06:05
Interactive : c++ & Python
# -*- encoding=UTF-8 -*-
#!/usr/bin/env python
from Hello import *; # import internal c++ module
a = World()
a.set("Liudx")
print("Hello", a.greet())
print(identity(red), identity(color(2)), identity(color.blue))
k = a.t
k.a = 10;
@Liudx1985
Liudx1985 / C++.sublime-build
Created September 3, 2014 02:37
C++.sublime-build for ST3
{
"cmd": ["g++", "-std=c++1y", "${file}", "-O2", "-Wall", "-o", "${file_path}/${file_base_name}"], // For GCC On Windows and Linux
//"cmd": ["CL", "/Fo${file_base_name}", "/O2", "${file}"], // For CL on Windows Only
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"variants":
[
{
@Liudx1985
Liudx1985 / fibonacci.
Last active August 29, 2015 14:05
Fibonacci性质
Fibonacci f(n+1)=f(n)+f(n-1) n >= 1
1. sum(f(n)^2) = f(n)*f(n+1)
证明如下,面积之和相等
# 绘图代码如下
import matplotlib.pyplot as plt
from matplotlib.path import Path
import matplotlib.patches as patches
@Liudx1985
Liudx1985 / clear_dir.py
Last active August 29, 2015 14:05
work file-directory ,clear or zip files.
# -*- coding:UTF-8 -*-
#!/usr/bin/env python
'''
Clear the directory using filter
'''
import os.path
import sys,os
import stat
import re
@Liudx1985
Liudx1985 / Binomial.cxx
Created August 12, 2014 08:34
计算二项式系数C(n,k)
#include <vector>
#include <iostream>
#include "d:/workspace/dxh/testUlt.h"
using namespace std;
//计算二项式系数C(n,k)
int Binomial(int n, int k) {
int result[n + 1][k + 1];
for(int i = 0; i <= n; ++i) //按行来填矩阵
{
@Liudx1985
Liudx1985 / hash_2_3.cxx
Last active August 29, 2015 14:05
hash_pair
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
// 双射函数
// proven :
// as
#lang racket
; applicative-order Y-combinator.
; Y: The function that takes a function f and returns f (f (f (f (···))))
(define Y
(lambda (le)
((lambda (f) (f f))
(lambda (f)
(le (lambda (x) ((f f) x)))))))
@Liudx1985
Liudx1985 / interpreter.scm
Created May 23, 2014 09:05
basical scheme interpreter
#lang racket
;;; 以下三个定义 env0, ent-env, lookup 是对环境(environment)的基本操作:
;; 空环境
(define env0 '())
;; 扩展。对环境 env 进行扩展,把 x 映射到 v,得到一个新的环境
(define ext-env
(lambda (x v env)
(cons `(,x . ,v) env)))