Skip to content

Instantly share code, notes, and snippets.

View chenfengyuan's full-sized avatar

Fengyuan Chen chenfengyuan

View GitHub Profile
@chenfengyuan
chenfengyuan / build-hsdis-macos.sh
Created January 10, 2020 08:27 — forked from rabbitcount/build-hsdis-macos.sh
Java 10 HotSpot Disassembly on macOS Mojave
#!/bin/bash -e
# Download OpenJDK Reference Implementation Sources from
# http://jdk.java.net/java-se-ri/10
curl -O https://download.java.net/openjdk/jdk10/ri/openjdk-10_src.zip
# Navigate to the hsdis sources
unzip openjdk-10_src.zip
cd openjdk/src/utils/hsdis
class A():
def __del__(self):
pass
def foo():
a=A()
b=A()
a.a=b
b.a=a
b.data = [0] * 1000 * 1000 * 100
import time, gc
@chenfengyuan
chenfengyuan / dvorak.reg
Created April 6, 2016 05:28 — forked from hotpxl/dvorak.reg
Dvorak Keyboard Layout
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"ScanCode Map"=hex:00,00,00,00,00,00,00,00,22,00,00,00,2d,00,30,00,24,00,2e,00,\
11,00,33,00,33,00,11,00,12,00,20,00,34,00,12,00,1b,00,0d,00,0d,00,1b,00,16,\
00,21,00,17,00,22,00,20,00,23,00,1a,00,0c,00,2e,00,17,00,23,00,24,00,14,00,\
25,00,31,00,26,00,35,00,1a,00,30,00,31,00,13,00,18,00,26,00,19,00,2f,00,34,\
00,28,00,10,00,0c,00,28,00,19,00,13,00,18,00,1f,00,1f,00,27,00,2c,00,35,00,\
15,00,14,00,22,00,16,00,25,00,2f,00,10,00,2d,00,21,00,15,00,27,00,2c,00,00,\
00,00,00
@chenfengyuan
chenfengyuan / wrong_max.cc
Created November 19, 2015 04:15
wrong way of using std::max
#include <algorithm>
#include <iostream>
struct C{
int v{};
C(int v_):v{v_}{
std::cout << "C()[" << v << "]\n";
}
C(const C &)=delete;
bool operator<(C const & o) const{
return v < o.v;
#include <stdio.h>
#include <pwd.h>
int main()
{
struct passwd *p;
p = getpwnam("root");
if (p == NULL) {
printf("no root!\n");
} else {
printf("root is %d\n", p->pw_uid);
#include <iostream>
#if defined(__clang__)
enum { max_depth = 256};
#else
enum { max_depth = 100};
#endif
#define INIT_REGISTER(REG) \
template<typename T, int N> \
struct REG:REG<T, N-1>{ \
@chenfengyuan
chenfengyuan / main.cpp
Created January 15, 2015 06:44
boost use callback functions in stackfull coroutine
#include <iostream>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/asio/spawn.hpp>
#include <memory>
void bar(boost::asio::io_service &io, std::function<void()> cb){
auto ptr = std::make_shared<boost::asio::deadline_timer>(io, boost::posix_time::seconds(1));
ptr->async_wait([ptr, cb](const boost::system::error_code&){cb();});
}
%lex
%%
\s+ {}
(AND|OR) { return 'LOG'; }
[a-zA-Z]+ { return 'VAR'; }
"(" return '('
")" return ')'
"!" return '!'
<<EOF>> { return 'EOF'; }
@chenfengyuan
chenfengyuan / tuple.cc
Created January 1, 2014 02:51
clang++ -std=c++11 -Wall -Wextra -stdlib=libc++ -O2 tuple.cc -o tuple.out
#include <tuple>
#include <memory>
int main(void){
using namespace std;
tuple<unique_ptr<char []>> b;
}
#include <tuple>
#include <memory>
int main(void){
using namespace std;
unique_ptr<char[]> a(new char[3]);
make_tuple(move(a));
}