Skip to content

Instantly share code, notes, and snippets.

View congdanhqx-zz's full-sized avatar

DOAN Tran Cong Danh congdanhqx-zz

View GitHub Profile
const char* format(int digit) {
switch (digit) {
case 6:
return "%06d";
case 4:
return "%04d";
case 5:
return "%05d";
case 7:
return "%07d";
@congdanhqx-zz
congdanhqx-zz / gist.cs
Created September 4, 2013 17:17
test2
[Extension("This extension enables Github Gist support for BlogEngine.NET.", "1.0", "Cong Danh")]
public class GistExtension
{
public GistExtension()
{
Post.Serving += Post_Serving;
}
void Post_Serving(object sender, ServingEventArgs e)
{
@congdanhqx-zz
congdanhqx-zz / template_get_max.cpp
Last active December 22, 2015 14:09
Example for C++ Template.
#include <iostream>
using namespace std;
template <class T>
T GetMax (T a, T b) {
T result;
result = (a > b) ? a : b;
return result;
}
template <class identifier>
return_data_type function_name(param_type param_name, ...) {
// function declaration
return result_value;
}
template <typename identifier>
return_data_type function_name(param_type param_name, ...) {
// function declaration
return result_value;
}
#include <iostream>
using namespace std;
template <class T>
int get_age(T obj) {
return obj.age;
}
class Person {
public:
public static class TypeExtensions
{
/// <summary>
/// Determine whether a type is simple (String, Decimal, DateTime, etc)
/// or complex (i.e. custom class with public properties and methods).
/// </summary>
/// <see cref="http://stackoverflow.com/questions/2442534/how-to-test-if-type-is-primitive"/>
public static bool IsSimpleType(
this Type type)
{
@congdanhqx-zz
congdanhqx-zz / Shuffle.cs
Last active December 28, 2015 21:19 — forked from anonymous/Shuffle
Shuffle An Array in C#
/// <summary>
/// Shuffle an <seealso cref="Array"/> of type <typeparamref name="T"/>
/// then return it for chaining.
/// </summary>
/// <typeparam name="T">Type of element in array.</typeparam>
/// <param name="array">The array which need to shuffle. This array will be modified.</param>
/// <returns>The modified array. It's the same reference with the input array.</returns>
public T[] Shuffle<T>(T[] array)
{
Random rnd = new Random();
@congdanhqx-zz
congdanhqx-zz / alignment.cpp
Last active August 29, 2015 13:57
Example for C/C++ keywords
#include <iostream>
using namespace std;
struct first {
char first_char;
int an_int;
char second_char;
};
struct second {
@congdanhqx-zz
congdanhqx-zz / dependent.cpp
Last active August 29, 2015 13:57
Example for template, callback function
template<class Container>
void doWork(Container& container)
{
Container::iterator it;
Container::iterator * it_ptr;
}
struct Person
{
static int iterator;
@congdanhqx-zz
congdanhqx-zz / private_robber.cpp
Last active July 25, 2016 10:03
How to access private member in C++
#include <iostream>
template <class Tag, typename Tag::type Value>
struct PrivateRobber {
friend typename Tag::type get(Tag) {
return Value;
}
};
class Item {