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 / tie_from.cc
Created Sep 14, 2013
Simulate std::tie's functionality for the input iterators.
View tie_from.cc
#include <tuple>
template <typename Iter, typename T1>
inline auto tie_from(Iter it, T1& t1)
-> std::tuple<T1&>
{
t1 = *it;
return std::tuple<T1&>(t1);
}
@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_vector.cc
Created Aug 16, 2013
Use variadic template instead of initializer_list to handle movable objects.
View make_vector.cc
#include <type_traits>
#include <vector>
template <typename V, typename T1>
inline void back_pusher(V& v, T1 t1)
{
v.push_back(std::move(t1));
}
template <typename V, typename T1, typename... T2>
@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 / less.in
Created Jun 25, 2013
Less configuration file; compile it with lesskey.
View less.in
#line-edit
^A home
^E end
\ef word-right
\eb word-left
\ed word-delete
^W word-backspace
#env
LESS = -i
View popcount.cc
#include <limits>
#include <climits>
#include <type_traits>
template <int bit>
struct fill_bits
{
template <typename Int>
static constexpr auto apply(Int n) -> Int
{
@lichray
lichray / pow2_roundup.cc
Last active Dec 18, 2015
Round an integer up to the closest 2's power.
View pow2_roundup.cc
#include <limits>
#include <type_traits>
template <int bit>
struct or_shift
{
template <typename Int>
static constexpr auto apply(Int n) -> Int
{
return or_shift<bit / 2>::apply(n | (n >> bit));
@lichray
lichray / make_unique.cc
Last active Dec 15, 2015
Modified from N3588, make_unique; a syntax enthusiast's work.
View make_unique.cc
#include <type_traits>
#include <iostream>
#include <memory>
struct default_init_t {};
default_init_t default_init;
template <typename T, typename = void>
struct make_unique;
@lichray
lichray / python_startup.py
Created Feb 26, 2013
setenv PYTHONSTARTUP this_file
View python_startup.py
import atexit
import os
import readline
import rlcompleter
hist_path = os.path.expanduser("~/.python/history")
readline.parse_and_bind("tab: complete")
readline.set_history_length(1000)
if os.path.exists(hist_path):
@lichray
lichray / linux-gtk-bluecurve-theme.fc7.shar
Created Dec 1, 2012
Updated x11-themes/linux-gtk-bluecurve-theme, works for linux-f10
View linux-gtk-bluecurve-theme.fc7.shar
# This is a shell archive. Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file". Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
# linux-gtk-bluecurve-theme.fc7
# linux-gtk-bluecurve-theme.fc7/distinfo.i386
# linux-gtk-bluecurve-theme.fc7/Makefile
You can’t perform that action at this time.