Skip to content

Instantly share code, notes, and snippets.

@chenshuo
chenshuo / tex-endcases.diff
Created December 13, 2019 23:30
Diff for 'end' -> 'endcases'
--- tex.web 2019-09-09 14:16:36.022037462 -0700
+++ tex2.web 2019-12-13 09:39:24.865189980 -0800
@@ -1956,7 +1956,7 @@
end;
"R":print_esc("nonstopmode");
"S":print_esc("scrollmode");
-end; {there are no other cases}
+endcases; {there are no other cases}
print("..."); print_ln; update_terminal; return;
end
@chenshuo
chenshuo / multiarray.cc
Last active October 16, 2023 14:29
MultiArray
#include <assert.h>
#include <array>
#include <functional>
#include <numeric>
template<typename T, int N>
class MultiArrayBase
{
public:
MultiArrayBase(T* data, const std::array<int, N>& dim)
@chenshuo
chenshuo / tree.cc
Last active October 29, 2020 15:14
expr tree
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <deque>
struct Node
{
Node(char v) : val(v) {}
bool isOperator() const
@chenshuo
chenshuo / nontype.cc
Last active August 28, 2017 20:44
Array as non-type template argument in C++17
#include "nontype.h"
const char tag[] = "abc";
int main()
{
}
@chenshuo
chenshuo / ThreadTest.java
Last active November 20, 2016 02:52
Two threads
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
public class ThreadTest {
enum Work {
RUN, STOP
}
static class Worker implements Runnable {
@chenshuo
chenshuo / gunzip.cc
Created July 12, 2016 18:19
inplace gunzip
#include <assert.h>
#include <fcntl.h>
#include <stdio.h>
#include <zlib.h>
#include <boost/noncopyable.hpp>
#include <deque>
// FIXME: re-implement this with disk buffer.
class Buffer : boost::noncopyable
{
@chenshuo
chenshuo / khash.hpp
Last active July 13, 2020 06:28
khash in C++
#pragma once
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <type_traits>
typedef uint32_t khint_t;
typedef khint_t khiter_t;
@chenshuo
chenshuo / 24.cc
Created November 6, 2015 18:41
Calculate 24 points.
#include <boost/rational.hpp>
#include <iostream>
#include <vector>
#include <stdio.h>
using boost::rational;
using std::cout;
using std::vector;
typedef vector<rational<int>> Numbers;
@chenshuo
chenshuo / badthreadpool.cc
Last active May 4, 2016 06:38
Bad thread pool example from C++ Concurrency in Action, it's a busy-loop.
#include <atomic>
#include <mutex>
#include <condition_variable>
#include <memory>
#include <queue>
#include <thread>
#include <unistd.h>
// Listing 4.5
template<typename T>
@chenshuo
chenshuo / intrusive1.cc
Created March 11, 2015 05:33
intrusive ptr
#include <string>
#include <unordered_set>
#include <boost/intrusive_ptr.hpp>
#include <boost/noncopyable.hpp>
#include <gperftools/malloc_extension.h>
#include <assert.h>
#include <string.h>