Skip to content

Instantly share code, notes, and snippets.

@gwang
gwang / index.html
Created December 20, 2015 18:33
a simple demo on how to use React.js components
<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>React Tutorial</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.3/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.3/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
@gwang
gwang / dedup.c
Created August 30, 2015 04:05
find if there is any repeated character in a given ascii string
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/* c implementation to test is an ASCII string has deplicated characters */
/**
* [main description]
* @param argc [number of argument]
* @param argv [argument values]
@gwang
gwang / adjust_time_stamp.rb
Last active August 29, 2015 21:53
Adjust the time stamps of the subtitles (srt) file
require 'pp'
require 'time'
class Item
attr_accessor :index, :start_time, :end_time, :text
def initialize(list)
@index = list[0]
@start_time, @end_time = list[1].split(' --> ').map{|a1| Time.parse(a1)}
@text = list[2..-1].join(' ')
@gwang
gwang / restore_icons.bat
Created August 26, 2015 04:54
Why are icons missing for certain programs in Win7?
rem Try the following.
rem Open Notepad and paste the below code.
taskkill /F /IM explorer.exe
cd /d %UserProfile%\AppData\Local
attrib –h IconCache.db
del IconCache.db
start explorer
rem save the file as a .bat file on your desktop. Then open explorer and navigate
@gwang
gwang / dynamic.fan
Last active August 29, 2015 14:28
Fantom metaprogramming example
/**
* Created by gwang2 on 8/24/2015.
* The code was based on the book "The ThoughWorks Anthology 2" with a minor bug fix. (see comments below)
*/
class XmlBuilder {
Str content
Int indent
new make() { this.content = ""; this.indent = 0}
@gwang
gwang / index.md
Last active August 29, 2015 14:28
ruby and rails resources
{
"in_process_packages":
[
],
"installed_packages":
[
"AdvancedNewFile",
"Alignment",
"All Autocomplete",
"Autoprefixer",
@gwang
gwang / MarkdownEditing.md
Last active August 29, 2015 14:27
sublime 3 tips & tricks

Problem

The MarkdownEditing plugin by default use a theme that becomes annoying when your sublime system theme is of a dark one such as Centurion. More problematic, the plugin's default settings are not editable since it was not automatically saved in the file sysetm c:\Users\username\Appdata\Roaming\Sublime Text 3\Packages.

Fix

  1. Install the PackageResourceViewer plugin
  2. ctrl+shift+p and type prv to bring the PackageResourceViewer up, find MarkdownEditing and hit return. Now the setting files are saved in the file system.
  3. Open c:\Users\username\Appdata\Roaming\Sublime Text 3\Packages\MarkdownEditing\Markdown.sublime-settings, and make the following changes:
@gwang
gwang / expand.c
Created August 18, 2015 07:19
Expend (x+y)^n for a given n
#include <stdlib.h>
#include <stdio.h>
int combine(int n, int m)
{
int s1, s2, i;
s1=s2=1;
for (i = m+1; i<=n; i++) s1 *= i;
for (i = 1; i<=(n-m); i++) s2 *= i;
@gwang
gwang / reverse.cpp
Created August 18, 2015 07:16
reverse a string in C++
#include <string>
#include <iostream>
using namespace std;
void reverse(string s)
{
cout << "input = " << s << endl;
cout << "size = " << s.length() << endl;