Skip to content

Instantly share code, notes, and snippets.

@yangacer
yangacer / cxx14-serialization.cpp
Created July 24, 2019 08:30
C++14 De/serialization structures made simple
#include <iostream>
#include <sstream>
#include <string>
#include <tuple>
template <size_t First, size_t Last>
struct ReadAux {
template <typename Tuple>
static auto& Exec(std::istream& os, Tuple&& args) {
os >> std::get<First>(args);
#!/usr/bin/env python
def main():
years_remain = int(raw_input('Years remain: '))
rental_price = int(raw_input('Rental price (month): '))
construction_value = (rental_price * 12) / (1.0 / years_remain)
print 'Construction value: {:,}'.format(construction_value)
land_quota = float(raw_input('Land quota (m^2): '))
land_announced_value = int(raw_input('Land anno. valuation (/m^2): '))
land_value = (land_announced_value / 0.9) * land_quota
@yangacer
yangacer / preview-event.html
Last active October 6, 2017 16:40
Preview event test sample
<html>
<style>
body {
display: flex;
flex-flow: row wrap;
}
.container {
width: 30%;
height: 400px;
@yangacer
yangacer / lru_sub_opt.cpp
Created September 11, 2016 06:20
Sloppy LUR impl
#include <iostream>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
using namespace std;
template<typename T>
struct lru {
@yangacer
yangacer / profiler.cpp
Created July 16, 2016 14:07
Mini C++ profiler (support multicore)
struct profiler {
profiler() : m_start{chrono::high_resolution_clock::now()} {
}
size_t til_now() const {
return chrono::duration_cast<chrono::milliseconds>(
chrono::high_resolution_clock::now() - m_start).count();
}
chrono::high_resolution_clock::time_point m_start;
@yangacer
yangacer / copy_move_observer.cpp
Last active July 16, 2016 13:47
Utility for observing C++ object copying/moving
#include <vector>
#include <string>
#include <iostream>
using namespace std;
struct obs {
obs() : m_mv(0), m_cp(0) { m_regs.insert(this); }
obs(obs const &cp) { m_regs.insert(this); m_cp++; m_total_cp++;}
obs(obs &&mv) { m_regs.insert(this); m_mv++; m_total_mv++;}
@yangacer
yangacer / utf8_to_unicode_cp.cpp
Last active April 19, 2016 16:10
UTF8 to Unicode codepoint
#include <iostream>
#include <string>
using namespace std;
uint32_t to_unicode(size_t *bytes, char const *utf8)
{
if (!utf8 || !*utf8) {
*bytes = 0;
return 0;
@yangacer
yangacer / jsonrpc_via_requests.py
Created June 10, 2015 10:10
JSONRPC over HTTP client invoker (within requests library)
import json
import requests
import functools
"""
Example:
cli = jsonrpc('http://rpcserver.com:6666')
try:
resp = cli.echo(hello='world')
@yangacer
yangacer / sortable.js
Last active August 29, 2015 14:02
Mini sort table with jquery
function sortable(table_dom, column_types, default_ordering) {
var rows = $(table_dom).find('tbody tr')
var dataset = [];
for (var i = 0; i < rows.length; ++i) {
var vals = $(rows[i]).find('td').toArray().map(function(v){
// console.log(arguments);
return v.innerText;
});
dataset.push(vals);
@yangacer
yangacer / impl.c
Created January 2, 2014 02:56
Member function with pure C
#include "impl.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
struct obj_impl
{
int a;
};