Skip to content

Instantly share code, notes, and snippets.

#include <string.h>
#include <assert.h>
#include "subsample.h"
/* helper func: GCD(m,n) */
static int helper_gcd(int m, int n)
{
return (n == 0) ? m : helper_gcd(n, m % n);
}
@yohhoy
yohhoy / input.cpp
Created December 4, 2016 13:44
gcc 7.0(HEAD) -std=c++1z -03
#include <cstdio>
#include <string>
int main() {
using namespace std::literals::string_view_literals;
for (char c: "Hello"sv) {
std::printf("(%d)", c);
}
}
@yohhoy
yohhoy / input.cpp
Created December 4, 2016 13:46
gcc 7.0(HEAD) -std=c++1z -03
#include <cstdio>
#include <string>
int main() {
using namespace std::literals::string_literals;
for (char c: "Hello"s) {
std::printf("(%d)", c);
}
}
@yohhoy
yohhoy / vlafib.c
Last active July 5, 2022 10:27
Fibonacci with VLA on C99
#include <stdio.h>
size_t f(size_t, char [][*]);
size_t f(size_t n, char r[][2 < n ? f(n-2, 0) + f(n-1, 0) : 1])
{
return sizeof(*r);
}
int main()
@yohhoy
yohhoy / repr_pmf.cpp
Last active January 5, 2017 06:39
representation of pointer to member function
#define USE_GCC_ABI_DEMANGLE 1
#include <iostream>
#include <typeinfo>
#if USE_GCC_ABI_DEMANGLE
#include <cxxabi.h>
#endif
template <typename T, typename R, typename... Args>
void dump(R (T::*pmf)(Args...))
@yohhoy
yohhoy / checked_mutex.cpp
Created January 16, 2017 04:23
Mutex with recursive locking detection
#include <cassert>
#include <cstdlib>
#include <condition_variable>
#include <mutex>
#include <system_error>
#include <thread>
#define CHECKED_MUTEX_ISSUE_ABORT 0
@yohhoy
yohhoy / httpsv.py
Created February 9, 2017 09:11
http server with header dump
#!/usr/bin/env python3
from http import server
server_address = ('localhost', 8080)
class Handler(server.SimpleHTTPRequestHandler):
def do_GET(self):
print('-' * 79)
super(Handler, self).do_GET()
print(self.headers)
@yohhoy
yohhoy / jpegeval.sh
Last active March 25, 2017 15:16
RD-curve evaluation of libjpeg/mozjpeg encoder
#!/bin/bash
LIBJPEG=/usr/local/opt/jpeg/bin/cjpeg
MOZJPEG=/usr/local/opt/mozjpeg/bin/cjpeg
LIBJEPG_OPTS=""
MOZJPEG_OPTS=""
QRANGE=`seq 80 100`
# ImageMagick
IDENTIFY=/usr/local/opt/imagemagick/bin/identify
const char *n2b(unsigned n, int l) {
static char buf[32+1];
for (int i = 0; i < l; i++) {
buf[l - i - 1] = (n & 1) ? '1': '0';
n >>= 1;
}
buf[l] = '\0';
return buf;
}