Skip to content

Instantly share code, notes, and snippets.

@gwang
gwang / unique_permutations.cpp
Created September 1, 2016 04:06
LeeCode problems
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void printVector(vector<int> & data)
{
cout << "[";
for (int j = 0; j < data.size(); j++)
@gwang
gwang / gist_search.rb
Last active August 9, 2016 19:41
Search your gist host on gist.github.com
require 'open-uri'
require 'open_uri_redirections'
require 'certified'
require 'json'
require 'pp'
USERNAME = 'gwang'
query = ARGV.first.downcase
@gwang
gwang / FixGDB.md
Last active April 7, 2016 01:11
Build CodeBlocks from Source on Ubuntu 15.10 x64
  1. When using Cygwin and Codeblocks, the gdb.exe complains that cannot open /cygdrive/c/.../yourfile.cpp. [Refer to this stackoverflow page] (http://stackoverflow.com/questions/18559506/codeblocks-gdb-cannot-open-file-error).
  2. You can fix this porblem by: Create a registry key path at HKEY_CURRENT_USER\Software\Cygnus Solutions\Cygwin\ using the New->Key. 3. The under HKEY_CURRENT_USER\Software\Cygnus Solutions\Cygwin\mounts v2 create a string value
  3. Name: cygdrive prefix
  4. Value: /cygdrive
@gwang
gwang / instruction.md
Last active May 23, 2022 18:34
Use grub to fix boot failure of virtualbox Ubuntu guest
  1. Refer to this tutorial

  2. Commands:

    grub> set pager=1
    grub> ls
    (hd0) (hd0,msdos2) (hd0,msdos1)
    grub> ls (hd0,1)/
    lost+found/ bin/ boot/ cdrom/ dev/ etc/ home/  lib/
    lib64/ media/ mnt/ opt/ proc/ root/ run/ sbin/ 
    
@gwang
gwang / gvm_setup.md
Last active January 15, 2016 04:35
Golang GVM set up
  1. Refer to this link

    1. gvm pkgset create learning
    2. gvm pkgset use learning
    3. gvm pkgset list
    4. edit env gvm pkgenv learning
# original line
export GOPATH; GOPATH="/Users/james/.gvm/pkgsets/go1.2/learning:$GOPATH"
# new edited line
@gwang
gwang / method_override.go
Last active February 18, 2019 05:27
GoLang method inheritance and overridance
package main
import "fmt"
// Method inheritance in GoLang is particularly interesting:
// 1. If a struct A has an anonymous field of struct B, then an object of A has all the methods from B.
// Yes, that means you can call those methods of B directly without referring the field name,
// just as if those methods are native to A. (Refer to the struct Student in the example below.)
// 2. This does not work if the field is named though. (Refer to the struct Employee case in the
// example below. )
// 3. Then what happens if A has a method whose name overlaps with one of B's methods?
@gwang
gwang / call_func_by_name.go
Last active January 13, 2016 04:56
Golang: call functions by name using reflection
// refer to: http://mikespook.com/2012/07/function-call-by-name-in-golang/
func foo() {
// does something
}
func bar(int i1, int i2, int i3) {
// does something else.
}
func Call(m map[string]interface{}, name string, params ... interface{}) (result []reflect.Value, err error) {
@gwang
gwang / Git_trick.md
Last active January 3, 2018 18:03
Git tricks
  1. Remove a file/directory in the repo but not locally:
    1. git rm --cached filepath
    2. git rm --cached -r directory_path
  2. To undo adding a file or directory:
    1. git reset $file_or_dir_name
  3. Start a bitbucket repo with existing project in local directory
    1. create a repo with ${repo_name} in bitbucket web
    2. cd your_project_path
    3. git init
    4. git remote add origin git@bitbucket.org:${user_name}/${repo_name}.git
@gwang
gwang / PrimeGenerator.go
Last active December 29, 2015 22:25
Use Go channel to generate prime numbers
package main
import (
"fmt"
"runtime"
)
func main() {
runtime.GOMAXPROCS(4)
ch := make(chan int)
go generate(ch)
for {
Problem: after upgrading the Ubuntu guest (running on Windows 7 host) to 15.10,
1. The full screen mode stopped working;
2. The shared folder with windows host stopped working;
Fixes:
1. Upgraded to virtual box version 5.0.10 (the latest version at the time).
2. Install VirtualBox Guest Additional as usual
# sudo mount /dev/sr0 /media/cdrom
# cd /media/cdrom
# sudo ./VBoxLinuxAddtionRun