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 / 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 / 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 / .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 / 203.cc
Created Mar 24, 2017
"Two star programming" with no star
View 203.cc
#include <functional>
class Solution {
public:
ListNode* removeElements(ListNode* head, int val) {
auto ls = std::ref(head);
while (ls != nullptr) {
if (ls.get()->val == val) {
auto p = ls.get();
@lichray
lichray / generic_literals.cc
Created Feb 13, 2016
Produce type-generic character and string literals
View generic_literals.cc
#include <type_traits>
#include <utility>
namespace etude {
template<class... Fs>
struct overloaded_function_impl_;
template<>
struct overloaded_function_impl_<> {
template<class... Args,
@lichray
lichray / visit_at.cc
Last active Sep 11, 2015
Access tuple by runtime index
View visit_at.cc
#include <tuple>
#include <type_traits>
template <int Low, int High, int Mid = (Low + High) / 2, typename = void>
struct _visit_at;
template <int Low, int High, int Mid>
struct _visit_at<Low, High, Mid, std::enable_if_t<(Low > High)>>
{
template <typename... T>
@lichray
lichray / rsynclib.h
Last active Aug 29, 2015
librsync job reader & writer
View rsynclib.h
/*
* Copyright 2015 Rackspace, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@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
@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; });
You can’t perform that action at this time.