Skip to content

Instantly share code, notes, and snippets.

View puzzledqs's full-sized avatar

Shi Qiu puzzledqs

View GitHub Profile
{
// Themes
"color_scheme": "Packages/Theme - Flatland/Flatland Dark.tmTheme",
"theme": "Flatland Dark.sublime-theme",
// font
"font_size": 15.0,
// tabs and white spaces
"draw_white_space": "all",
@puzzledqs
puzzledqs / gist:10118763
Last active August 29, 2015 13:58
Remote an IPython Notebook

IPython Notebook has always been handy and cool for prototyping algorithms and running quick simulations, for it brings the best of two worlds -- the powerful interactive capability of IPython terminal, and the beautiful documentation enabled by Markdown. You can always check out the IPython website for existing and coming cool new features.

Simply put, IPython Notebook runs in a server-client mode. A IPython kernel (server) runs at the backend, and you connect to and interact with the kernel from your web browser through a localhost TCP port. The initialization is automated so you don't have to bother with setting up the whole enviroment by hand. Everytime you'd lide to start an IPython notebook, just type ipython notebook in the command line and the script will take care of the rest for you. That's pretty much the way I have been using ipython notebook up to now.

Last night, I started to think of the possibility of remote a IPython notebook, or strictly speaking,

  1. Install R
  2. Install rpy2. Rpy2 doesn't officially support windows. Follow this post as a workaround.
  3. In IPython, %load_ext rmagic and there you go.
@puzzledqs
puzzledqs / gist:11168305
Last active August 29, 2015 14:00
flush the Python stdout buffer
sys.stdout.flush()

This function will flush the output (e.g. print 'hello world') immdiately to the command line so that you can see the results of the program in real time.

@puzzledqs
puzzledqs / gist:93efee7fc582ac118a47
Last active August 29, 2015 14:02
Basic setup in Ubuntu

Basic setup in Ubuntu:

  1. Remote Desktop
  • sudo apt-get update
  • sudo apt-get install xrdp
  • sudo apt-get install gnome-session-fallback
  • echo "gnome-session --session=ubuntu-fallback" > ~/.xsession
  • sudo /etc/init.d/xrdp restart ** use gnome-session-quit --logout to log out
@puzzledqs
puzzledqs / gist:f0bd3fd239a21a35cbe7
Last active August 29, 2015 14:07
Get the path of a python script
import os
os.path.abspath(__file__)
os.path.realpath(__file__)
@puzzledqs
puzzledqs / gist:663fc7602fd6682b9237
Last active August 29, 2015 14:13
Pipe & Redirect

重定向操作符 描述

>    将命令输出写入到文件或设备(例如打印机)中,而不是写在命令提示符窗口或句柄中。 
<    从文件中而不是从键盘或句柄中读入命令输入。 
>>   将命令输出添加到文件末尾而不删除文件中的信息。 
>&   将一个句柄的输出写入到另一个句柄的输入中。 
<&   从一个句柄读取输入并将其写入到另一个句柄输出中。 
|    从一个命令中读取输出并将其写入另一个命令的输入中。也称作管道。 

0 是 &lt; 重定向输入操作符的默认句柄。 
@puzzledqs
puzzledqs / gist:a97174a4886aaca5177f
Last active August 29, 2015 14:13
create dll project in VS

C 和C++ 对应不同的调用约定,产生的修饰符也各不相同,如下:

调用约定 extern "C" 或 .c 文件 .cpp、.cxx 或 /TP
C 命名约定 (__cdecl) _test ?test@@ZAXXZ
Fastcall 命名约定 (__fastcall) @test@0 ?test@@YIXXZ
标准调用命名约定 (__stdcall) _test@0 ?test@@YGXXZ

__declspec(dllexport) __declspec(dllimport)一般也是使用宏的形式:

@puzzledqs
puzzledqs / gist:608705d18649439faa69
Last active December 18, 2015 04:50
Commands for Linux `screen'
screen -ls
screen -r
screen -x
screen -S socketname
Ctrl + A:
c -- create
k -- kill
d -- detach