Skip to content

Instantly share code, notes, and snippets.

@physacco
physacco / getch.c
Created November 8, 2016 07:15
Get char from stdin without pressing enter.
#include <stdio.h>
#include <termios.h>
int getch(void) {
int ch;
struct termios oldt;
struct termios newt;
tcgetattr(STDIN_FILENO, &oldt); /*store old settings */
newt = oldt; /* copy old settings to new settings */
@physacco
physacco / numeric_limits.cpp
Created September 19, 2016 11:33
Example of std::numeric_limits.
#include <iostream>
#include <limits>
template <typename T>
void test_limits() {
T min = std::numeric_limits<T>::min();
T max = std::numeric_limits<T>::max();
std::cout << "min: " << min << std::endl;
std::cout << "max: " << max << std::endl;
}
@physacco
physacco / about-erlang-references.txt
Created June 18, 2013 02:44
Erlang references are unique indentifiers. They are commonly used to identify timers, rpc calls, etc.
Erlang references are unique indentifiers. They are commonly used to
identify timers, rpc calls, etc.
make_ref() -> ref()
Returns an almost unique reference.
The returned reference will re-occur after approximately 2^82 calls;
@physacco
physacco / ando10.d
Created December 22, 2015 19:52
My solutions to paiza POH 7 in D language
import std.stdio;
long factorial(int n) {
long fac = 1;
foreach (i; 1..n+1) {
fac *= i;
}
return fac;
}
@physacco
physacco / ando10.rb
Last active December 17, 2015 11:39
My solutions to paiza POH 7
x=1;1.upto(gets.to_i){|i|x*=i};p x
@physacco
physacco / git-change-origin.md
Created May 16, 2013 06:56
Move the `origin' of a git repository to another host.

把一个git仓库的origin搬到另一台服务器上

  1. 在旧服务器上删除这个仓库

    rm -r /home/$USER/repo/$REPO

  2. 在新服务器上创建一个同名的仓库

    cd /home/$USER/repo git init --bare $REPO

@physacco
physacco / install_ruby-1.9.sh
Created May 9, 2013 09:09
Bash scripts for installing MRI ruby 1.9.3 & 2.0.0 from source.
#!/bin/bash
set -e
PREFIX="$HOME/local/ruby/1.9.3"
RUBY_DIST_URL="ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p392.tar.gz"
RUBY_DIST_PKG=`basename $RUBY_DIST_URL`
RUBY_DIST_DIR=`basename $RUBY_DIST_PKG .tar.gz`
@physacco
physacco / script_dir.sh
Created May 8, 2013 09:02
A utility function for getting the directory of the shell script itself.
#!/bin/bash
script_dir()
{
local SCRIPT_PATH=${BASH_SOURCE[0]}
while [ -L "${SCRIPT_PATH}" ]; do
SCRIPT_PATH=`readlink "$SCRIPT_PATH"`
done
local SCRIPT_DIR=`dirname "${SCRIPT_PATH}"`
@physacco
physacco / parse_config_file.py
Created May 6, 2013 06:44
Functions to parse config.py.
def parse_config_stream(str_or_file):
_myglobals, mylocals = {}, {}
exec str_or_file in _myglobals, mylocals
return mylocals
def parse_config_file(filename):
_myglobals, mylocals = {}, {}
with open(filename) as f:
exec f in _myglobals, mylocals
$ gem sources
*** CURRENT SOURCES ***
http://rubygems.org/
http://gems.github.com/
$ gem sources --remove http://rubygems.org/
http://rubygems.org/ removed from sources
$ gem sources --add http://ruby.taobao.org/