Skip to content

Instantly share code, notes, and snippets.

View leafbird's full-sized avatar

choi sung ki leafbird

View GitHub Profile
@leafbird
leafbird / formatting.js
Created April 1, 2013 05:04
string formatting function in JavaScript.
String.prototype.format = function () {
var formatted = this;
for (arg in arguments) {
formatted = formatted.replace("{" + arg + "}", arguments[arg]);
}
return formatted;
};
@leafbird
leafbird / default.html
Last active December 15, 2015 20:29
html 파일 만들 때 기본으로 타이핑하는 마크업들.
<!doctype html>
<html>
<head>
<title>Write Title Here.</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link class="include" rel="stylesheet" type="text/css" href="style.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js" type="text/javascript"></script>
</head>
<body>
function asyncMap( list, fn, cb_ ) {
var n = list.length
, result = []
, errState = null;
function cb (er, data) {
if (errState) return;
if (er) return cb_(errState = er);
results.push(data);
if (--n === 0) // 모든 리스트 처리 완료시
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
AllocConsole();
@leafbird
leafbird / fstream_utf8.cpp
Created June 25, 2013 15:25
std::fstream 계열로 파일 I/O를 할 때 utf-8인코딩을 사용하도록 설정하는 코드. 출처 : http://sockbandit.wordpress.com/2012/05/31/c-read-and-write-utf-8-file-using-standard-libarary/
#include <fstream>
#include <iostream>
#include <string>
#include <locale>
#include <codecvt>
...
// Write file in UTF-8
std::wofstream wof;
wof.imbue(std::locale(std::locale::empty(), new std::codecvt_utf8<wchar_t,0x10ffff,std::generate_header>));
@leafbird
leafbird / slnParser.cs
Created September 3, 2013 06:02
C#에서 visual studio 솔루션파일 파싱해주는 코드. 출처 : http://stackoverflow.com/questions/707107/library-for-parsing-visual-studio-solution-files
public class Solution
{
//internal class SolutionParser
//Name: Microsoft.Build.Construction.SolutionParser
//Assembly: Microsoft.Build, Version=4.0.0.0
static readonly Type s_SolutionParser;
static readonly PropertyInfo s_SolutionParser_solutionReader;
static readonly MethodInfo s_SolutionParser_parseSolution;
static readonly PropertyInfo s_SolutionParser_projects;
@leafbird
leafbird / Singleton.cs
Created March 5, 2014 10:59
...One approach is to use an idiom referred to as Double-Check Locking [Lea99]. However, C# in combination with the common language runtime provides a static initialization approach, which circumvents these issues without requiring the developer to explicitly code for thread safety.
// from http://msdn.microsoft.com/en-us/library/ff650316.aspx
public sealed class Singleton
{
private static readonly Singleton instance = new Singleton();
private Singleton(){}
public static Singleton Instance
{
@leafbird
leafbird / HttpClient.cpp
Last active August 29, 2015 14:13
HttpClient with boost::asio
#include "StdAfx.h"
#include "HttpClient.h"
namespace AsioHttp
{
using boost::asio::ip::tcp;
class Client::ClientImpl
{
@leafbird
leafbird / FunctionTraits.h
Last active August 29, 2015 14:14
Typelist: Implemented by variadic templates
#include "TypeList.h"
// from : https://functionalcpp.wordpress.com/2013/08/05/function-traits/
template<class F>
struct function_traits;
// function pointer
template<class R, class... Args>
struct function_traits<R(*)(Args...)> : public function_traits<R(Args...)> {
namespace Utility
{
using System;
using System.Linq.Expressions;
using System.Reflection;
public static class PropertySelector
{
public static PropertyInfo GetPropertyInfo<T>(this T obj, Expression<Func<T, object>> selector)
{