Skip to content

Instantly share code, notes, and snippets.

@XeCycle
XeCycle / README.md
Last active August 26, 2022 04:00
dump command line and environment

Part of an attempt to rewrite my mini-tools in rust.

TODO:

  • do I need to take *mut InitFrame instead of &mut self to avoid UB?
  • is it possible to do this in cargo, or make it multi-file in other ways, with LTO?
  • why an extraneous ud2 is generated for unreachable_unchecked? (look at objdump -d initf.o)
@XeCycle
XeCycle / output.txt
Last active March 10, 2021 07:06
cpython signal handlers while creating C resources?
$ python test_cffi_sig.py
resources created
Traceback (most recent call last):
File "/.../test_cffi_sig.py", line 41, in <module>
x = using_outp()
File "/.../test_cffi_sig.py", line 35, in using_outp
lib.my_create_resource_outp(out)
KeyboardInterrupt
release 42
@XeCycle
XeCycle / async-drive.py
Created January 3, 2019 09:16
Attempting to use py3 async-await with existing callback api
from types import coroutine
class CbWait(object):
def __init__(self):
self.coro = None
self.args = None
def recur(self, coro):
if self.args:
#include <type_traits>
#include <iostream>
int f(const int&)
{
return 1;
}
int f(int&&)
{
@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>,
@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 / 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 / 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 / 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 / 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;