Skip to content

Instantly share code, notes, and snippets.

View yen3's full-sized avatar

Yen3 yen3

  • Taiwan
View GitHub Profile
@yen3
yen3 / singleton.hpp
Last active August 29, 2015 14:03
multiple reference for a single object in C++
class Singleton{
public:
static const Singleton& getInstance(){
static Singleton single;
return single;
};
private:
Singleton():a(0){};
unsigned int a;
};
from __future__ import print_function
class Attribute(object):
def __init__(self):
pass
def main():
a = Attribute();
print(a.__dict__)
a.__setattr__("test", 5)
@yen3
yen3 / list_dir.hs
Last active August 29, 2015 14:22
List files in a directory recursively
module ListFiles where
import System.Directory
import System.FilePath.Posix
split:: [a] -> [Bool] -> ([a], [a])
split xs bs = foldr s ([], []) (zip xs bs)
where s (d, i) (y, z) = if i then (d:y, z) else (y, d:z)
isSpecialFile :: FilePath -> Bool
@yen3
yen3 / read_pbpaste.hs
Last active December 22, 2015 12:29
Read the contents from the clipboard in Mac OSX
-- Read the contents of clipboard
-- Ref: http://stackoverflow.com/questions/1712347/closest-equivalent-to-subprocess-communicate-in-haskell
import System.Process
processData :: String -> String
processData = (id :: String -> String)
processPaste :: (String -> String) -> IO ()
processPaste pd = do
@yen3
yen3 / read_pbpaste_2.hs
Created September 8, 2013 01:26
read the clipboard's contents
processPaste' :: (String -> String) -> IO ()
processPaste' pd = putStrLn . pd =<< readProcess "pbpaste" [] []
@yen3
yen3 / new_post_nikola.py
Last active December 23, 2015 01:49
Generate a new post with default contents in nikola.
#!/usr/bin/env python
DEFAULT_CONTENTS="""<!--
.. link:
.. description:
.. tags: all
.. date: $time
.. title: $title
.. slug: $slug
-->
@yen3
yen3 / base.html
Last active December 25, 2015 10:19
Simple practice for Flask + jQuery
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css" rel="stylesheet">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
@yen3
yen3 / p01.hs
Last active December 25, 2015 14:19
Project Euler
sol1 = takeWhile (<1000) $ filter (\x -> x `mod` 3 == 0 || x `mod` 5 == 0) [1..]
sol2 = takeWhile (<1000) [x| x<-[1..], x `mod` 3 ==0 || x `mod` 5 ==0]
@yen3
yen3 / install_cmd.hs
Last active December 27, 2015 05:59
Install commands for programming envrionment.
import Data.List
import System.Cmd
type ExecuteCmd = String
type Option = String
type OptionList = [Option]
data Command = Cmd ExecuteCmd OptionList
deriving (Show, Eq)
@yen3
yen3 / gist:3a264578e79e213a692135f98bd1a2a2
Created June 14, 2016 05:54 — forked from lttlrck/gist:9628955
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote