Skip to content

Instantly share code, notes, and snippets.

View juehan's full-sized avatar

John.L juehan

  • Sydney, Australia
View GitHub Profile
@juehan
juehan / GenericFactoryFunc
Created December 14, 2011 05:01
generic factory function
#include <memory>
#include <string>
#include <iostream>
//Example class
class Dog
{
public:
explicit Dog(std::string& name) : m_name(name), m_age(1){}
@juehan
juehan / move10.cpp
Created December 23, 2011 16:02
C++11 move sample01
#include <vector>
#include <ctime>
#include <iostream>
class X
{
private:
std::vector<int> m_vec;
public:
X() : m_vec(100000)
@juehan
juehan / PythonChallenge1.py
Created February 13, 2012 11:09
Python Challenge Level 1
from string import maketrans
intab = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
outtab = "CDEFGHIJKLMNOPQRSTUVWXYZAB"
transtab = maketrans(intab, outtab)
mystr = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."
mystrUpper = mystr.upper()
print mystrUpper.translate(transtab).lower()
@juehan
juehan / PythonChallenge02.py
Created February 13, 2012 11:53
Python Challenge Level2
f = open("pythonchallenge2.txt", "r")
l = []
try:
for line in f:
for c in line:
if c.isalpha():
l.append(c)
finally:
f.close()
@juehan
juehan / PythonChallenge3.py
Created February 13, 2012 15:16
Python Challenge Level 3
#Example: ....asdasfasBBBbCCClhasdheku....
#[a-z][A-Z]{3}([a-z])[A-Z]{3}[a-z]
import re
regex= "[a-z][A-Z]{3}([a-z])[A-Z]{3}[a-z]"
filename = "pythonchallenge3.txt"
try:
f = open(filename, "r")
readed = f.read()
@juehan
juehan / ThreadCPP11.cpp
Created February 13, 2012 23:06
C++11 Thread Example
#include <thread>
#include <iostream>
int main()
{
auto t1 = new std::thread([]
{
for(int i=0; i < 10; i++)
std::cout<<"Thread 1 ------>"<<std::endl;
});
@juehan
juehan / nswtime.py
Created February 15, 2012 15:08
Example to show how to change timezone using *nix environment variable
'''
module to get Sydney/Australia's local time.
This module is not portable as time.tzset() is not supported at Windows Environment but only at *nix.
Will be useful if deployment system is in different time zone to application's target time zone.
'''
import os
import time
from time import strftime, localtime
@juehan
juehan / PyGameMP3Player.py
Created February 20, 2012 13:02
MP3Player Using PyGame
'''
Created on 2012. 2. 19.
This module is for playing mp3 (limited) and wav formatted audio file
@author: John
'''
import pygame
def playsound(soundfile):
"""Play sound through default mixer channel in blocking manner.
This will load the whole sound into memory before playback
@juehan
juehan / HelloMusicActivity.java
Created February 26, 2012 09:52
Very Simple Android MP3 Player
package com.audroid.music;
import android.app.Activity;
import android.content.Context;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
@juehan
juehan / ListViewCodeSnippet.java
Created February 29, 2012 13:39
ListView based Android UI code
//...
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
File root = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
ListDir(root);
isPlaying = false;
c = getApplicationContext();
index = 0;