Skip to content

Instantly share code, notes, and snippets.

@gwang
gwang / gist:2657578
Created May 11, 2012 04:40
Multiplication Bingo in Ruby Using SAPI
# Using Windows SAPI
require 'win32/sapi5'
include Win32
v = SpVoice.new
data = Hash.new
(0..12).each { |i|
(0..12).each { |j|
p = i*j
data[p] = Array.new if data[p].nil?
@gwang
gwang / bingo.txt
Created May 11, 2012 04:43
Multiplication Bingo in Tcl Using SAPI
{0 {{0 0} {0 1} {0 2} {0 3} {0 4} {0 5} {0 6} {0 7} {0 8} {0 9} {0 10} {0 11} {0 12} {1 0} {2 0} {3 0} {4 0} {5 0} {6 0} {7 0} {8 0} {9 0} {10 0} {11 0} {12 0}}}
{1 {{1 1}}}
{2 {{1 2} {2 1}}}
{3 {{1 3} {3 1}}}
{4 {{1 4} {2 2} {4 1}}}
{5 {{1 5} {5 1}}}
{6 {{1 6} {2 3} {3 2} {6 1}}}
{7 {{1 7} {7 1}}}
{8 {{1 8} {2 4} {4 2} {8 1}}}
{9 {{1 9} {3 3} {9 1}}}
@gwang
gwang / per_com.rb
Last active December 22, 2015 01:28
compute the permutation and combination of a string (or a collection of characters)
def permutation(data, used=nil, prev='')
used = Array.new(data.size) if used == nil
(0..data.size-1).each do |i|
result = prev
if used[i] == false || used[i] == nil
used[i] = true
result += data[i]
if result.length == data.size
puts result
@gwang
gwang / gist:39ffce190d7d3a98b8b8
Last active August 29, 2015 14:14
Rotate a potentially large string about a pivot point
#include <stdlib.h>
#include <stdio.h>
void reverse(char *data, int start, int end)
{
int i; char tmp;
for (i=0; i<(end-start)/2; i++)
{
tmp = data[i+start];
@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;
@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 / 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:
{
"in_process_packages":
[
],
"installed_packages":
[
"AdvancedNewFile",
"Alignment",
"All Autocomplete",
"Autoprefixer",
@gwang
gwang / index.md
Last active August 29, 2015 14:28
ruby and rails resources
@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}