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 / Cpp11_RangeBasedForLoop.cpp
Created November 8, 2012 06:45
C++11 Range Based for loop
//Range Based For Loop Example (Run on VS2012)
#include <iostream>
#include <vector>
#include <algorithm>
template <typename T>
void printElement1(const T& collection)
{
std::cout<<"printElement using traditional for loop"<<std::endl;
@juehan
juehan / gist:3599168
Created September 2, 2012 13:59
C++11 coding style - default param, std algorithm, non-member function begin() and end()
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::vector;
using std::string;
@juehan
juehan / Cpp11Atomic.cpp
Created August 18, 2012 12:08
Use of C++11 atomic to handle shared resource under multi threaded environment.
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <thread>
#include <atomic>
using namespace std;
@juehan
juehan / emplaceback.cpp
Created June 29, 2012 13:51
std::vector::emplace_back() example
//Compiled with G++(GCC) 4.6.2
/*
* std::vector::emplace_back (since C++11)
*
* Appends a new element to the end of the container.
* The element is constructed in-place, i.e. no copy or move operations are performed.
* The constructor of the element is called with exactly the same arguments,
* as supplied to the function.
* */
@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;
@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 / 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 / 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 / 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 / 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()