Skip to content

Instantly share code, notes, and snippets.

Zhihao Yuan lichray

Block or report user

Report or block lichray

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@lichray
lichray / update-clouddns.py
Created Aug 23, 2013
(alpha) Dynamic DNS using Rackspace Cloud DNS
View update-clouddns.py
#!/usr/bin/env python
INTERVAL = 300
import clouddns
import requests
try:
from gi.repository import GObject as gobject
except ImportError:
@lichray
lichray / make_array.cc
Last active Apr 8, 2019
Factory function of std::array
View make_array.cc
#include <array>
#include <functional>
template <typename... T>
using common_type_t = typename std::common_type<T...>::type;
template <typename T>
using remove_cv_t = typename std::remove_cv<T>::type;
template <bool, typename T, typename... U>
@lichray
lichray / binary_literal.cc
Created Nov 27, 2012
User-defined binary literal in C++11
View binary_literal.cc
#include <iostream>
// http://stackoverflow.com/questions/537303/binary-literals
template<char... digits>
struct conv2bin;
template <char... digits>
constexpr int operator"" _b() {
return conv2bin<digits...>::value;
}
@lichray
lichray / fraction.cc
Last active Nov 2, 2018
Fraction class (MSVC support is experimental)
View fraction.cc
#include <limits>
#include <ostream>
#include <stdexcept>
#include <system_error>
#include <type_traits>
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
@lichray
lichray / iota_n.cc
Last active Sep 9, 2018
generate_n is a better iota_n.
View iota_n.cc
#include <algorithm>
#include <vector>
#include <iterator>
#include <iostream>
int main()
{
std::vector<int> v;
// instead of asking for iota_n(std::back_inserter(v), 10, 1);
std::generate_n(back_inserter(v), 10, [n = 0]() mutable { return ++n; });
@lichray
lichray / csv.cc
Created Aug 10, 2018
A tiny CSV data reader for online coding tests
View csv.cc
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <errno.h>
#include <iterator>
#include <stdlib.h>
namespace csv
{
@lichray
lichray / patch-mylogo
Created Sep 26, 2012
Customize xscreensaver's unlock dialog image.
View patch-mylogo
@lichray
lichray / .gitconfig
Created Feb 7, 2018
Common git aliases
View .gitconfig
[alias]
st = status
fix = commit --amend -C HEAD
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative
discard = reset HEAD --
@lichray
lichray / version.py
Last active Nov 18, 2017 — forked from ludwigschwardt/version.py
Produce a setuptools-compatible package version number based on git tags
View version.py
"""Calculate the current package version number based on git tags.
If possible, use the output of `git describe` modified to conform to the
versioning scheme that setuptools uses (see PEP 386). Releases must be
labelled with annotated tags (signed tags are annotated) of the following
format:
v<num>(.<num>)+ [ {a|b|c|rc} <num> (.<num>)* ]
If `git describe` returns an error (likely because we're in an unpacked copy
@lichray
lichray / static_if.cc
Created Sep 13, 2014
Implement static_if using C11 generic selection
View static_if.cc
#include <type_traits>
#include <tuple>
#include <iostream>
// Link: https://github.com/aeyakovenko/notes
//count arguments
//COUNT_ARGS :: ... -> Int
#define COUNT_ARGS(...) COUNT_ARGS_(,##__VA_ARGS__,6,5,4,3,2,1,0)
#define COUNT_ARGS_(z,a,b,c,d,e,f,cnt,...) cnt
You can’t perform that action at this time.