Skip to content

Instantly share code, notes, and snippets.

View lichray's full-sized avatar

Zhihao Yuan lichray

View GitHub Profile
@lichray
lichray / tie_from.cc
Created September 14, 2013 15:37
Simulate std::tie's functionality for the input iterators.
#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 August 23, 2013 21:08
(alpha) Dynamic DNS using Rackspace Cloud DNS
#!/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 August 16, 2013 02:37
Use variadic template instead of initializer_list to handle movable objects.
#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 August 29, 2023 16:37
Factory function of std::array
#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 June 25, 2013 21:26
Less configuration file; compile it with lesskey.
#line-edit
^A home
^E end
\ef word-right
\eb word-left
\ed word-delete
^W word-backspace
#env
LESS = -i
#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 December 18, 2015 06:08
Round an integer up to the closest 2's power.
#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 December 15, 2015 06:49
Modified from N3588, make_unique; a syntax enthusiast's work.
#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 February 26, 2013 04:34
setenv PYTHONSTARTUP this_file
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 December 1, 2012 16:25
Updated x11-themes/linux-gtk-bluecurve-theme, works for linux-f10
# 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