Skip to content

Instantly share code, notes, and snippets.

@XeCycle
XeCycle / comic-mplayer.sh
Created February 29, 2012 14:25
SJTU Comic VLC TV playlist transformed for use with mplayer.
#!/bin/bash
# Configurations
player=mplayer
playlisturl='http://comic.sjtu.edu.cn/vlc/pl_xspf.asp'
TMPDIR=$(mktemp -d)
cd $TMPDIR
cat > comic-vlc.xslt <<EOF
@XeCycle
XeCycle / scannable-stream.js
Created October 12, 2015 08:27
something like stream.readline(), returning a promise.
import {Writable} from "stream";
// scanner returns remaining string if succeeded, null/undefined otherwise
class ScanningState {
constructor(buf, scanner) {
this.buf = buf;
this.scanner = scanner;
}
scan() {
throw new Error("Another scan in progress");
44022 silly gunzTarPerm modified mode [ 'lib/dependencies/RequireResolveDependency.js', 438, 420 ]
44023 silly gunzTarPerm extractEntry library/es7/array.js
44024 silly gunzTarPerm modified mode [ 'library/es7/array.js', 438, 420 ]
44025 silly gunzTarPerm extractEntry library/es7/index.js
44026 silly gunzTarPerm modified mode [ 'library/es7/index.js', 438, 420 ]
44027 silly gunzTarPerm extractEntry node_modules/npmlog/node_modules/gauge/node_modules/lodash.padleft/node_modules/lodash._createpadding/index.js
44028 silly gunzTarPerm extractEntry node_modules/npmlog/node_modules/gauge/node_modules/lodash.padleft/node_modules/lodash._createpadding/node_modules/lodash.repeat/package.json
44029 silly gunzTarPerm extractEntry node_modules/node-pre-gyp/node_modules/request/node_modules/mime/types/mime.types
44030 silly gunzTarPerm extractEntry node_modules/node-pre-gyp/node_modules/request/node_modules/mime/types/node.types
44031 silly gunzTarPerm extractEntry features-json/midi.json
@XeCycle
XeCycle / do-notation-safe.sjs
Created October 30, 2015 08:33
An emulation of do notation that remains valid javascript
macro DO {
rule { ($name:ident <- $expr:expr, ret($any...)) } => { ($expr).map($name => ($any...)) }
rule { ($name:ident <- $expr:expr, $any...) } => { ($expr).chain($name => DO($any...))}
rule { ($expr:expr, ret($any...)) } => { ($expr).map(() => ($any...)) }
rule { ($expr:expr, $any...) } => { ($expr).chain(() => DO($any...)) }
rule { ($expr:expr) } => { ($expr) }
}
export DO;
@XeCycle
XeCycle / spread-call.cc
Created December 31, 2015 01:29
apply a tuple of parameters to a function
namespace tuple_util_impl {
template <size_t... i, class Function, class Tuple>
auto spread_call(std::index_sequence<i...>, Function f, Tuple&& t)
-> decltype(f(std::get<i>(t)...))
{
return f(std::get<i>(t)...);
}
@XeCycle
XeCycle / bench.cc
Last active February 2, 2016 05:54
#include <string>
#include <algorithm>
#include <chrono>
#include <iostream>
#include "crc-32.hh"
std::chrono::duration<unsigned long long, std::micro>
constexpr operator""_us(unsigned long long x)
{
@XeCycle
XeCycle / limit-scope.cc
Created February 23, 2016 02:58
One way to limit scope of dependency
auto x = ([](Dependency a) {
Foo f(a);
Bar b(a);
return f+b;
})({});
long_computation(x);
@XeCycle
XeCycle / demo.cc
Created March 15, 2016 06:55
flow-sink style demo
#include <iostream>
#include "output-iterator-adaptor.hh"
#include "map.hh"
int main()
{
auto f = [](auto x) { return x+1; };
@XeCycle
XeCycle / c-string-union.cc
Created March 22, 2016 01:57
C interop string class
#include <cstddef>
#include <string>
#include <memory>
#include <type_traits>
#include <vector>
#include <iostream>
#include <cassert>
template <class Char, class Traits=std::char_traits<Char>,
#include <type_traits>
#include <iostream>
int f(const int&)
{
return 1;
}
int f(int&&)
{