Skip to content

Instantly share code, notes, and snippets.

unsigned char my_clamp(const int x) {
return (x < 0) ? 0 : ((x > 0xFF) ? 0xFF : (unsigned char) x);
}
int f0(unsigned int *regs){
int r;
int ro;
int cv;
// ip: 0
// 0,4,29,DUK_OP_ADD_RC
regs[29]=regs[4]+15;
~/src/ChakraCore # time ./build.sh -t --cxx=$(which clang++) --cc=$(which clang) --embed-icu -j 1
Custom CXX /usr/bin/clang++
Custom CC /usr/bin/clang
Build path: /root/src/ChakraCore/out/Test
-- /root/src/ChakraCore/bin/ch/DbgController.js.h is up to date. skipping.
Compile Target : System Default
Generating Test makefiles
-- found ICU libs: deps/icu/source/output/include//../lib/
-- Configuring done
@cosinusoidally
cosinusoidally / example.js
Last active April 3, 2018 16:55
Garbage collector safe example embedding ChakraCore in Spidermonkey shell using js-ctypes
/*
Tested against release/1.4 branch of https://github.com/Microsoft/ChakraCore
commit: 6f4c890505a58bbf198035d4b93bf8a726033af3
The below program will work on x86_64 Linux. It demonstrates how to safely call
in to libChakraCore from Spidermonkey using js-ctypes. Because the ChakraCore
GC scans the stack for JsValueRefs we must allocate JsValueRefs on the C stack.
When I say C stack I mean in the memory region between the current stack
pointer and the initial value of the stack pointer when the program started.
@cosinusoidally
cosinusoidally / hacky.js
Last active January 2, 2017 07:11
Horrible hacky code calling libChakraCore.so from Mozilla's jsshell
// get Spidermonkey from here:
// https://ftp.mozilla.org/pub/firefox/candidates/45.6.0esr-candidates/build1/jsshell-linux-x86_64.zip
// SHA512SUM and signature here:
// https://ftp.mozilla.org/pub/firefox/candidates/45.6.0esr-candidates/build1/linux-x86_64/en-US/firefox-45.6.0esr.checksums
// https://ftp.mozilla.org/pub/firefox/candidates/45.6.0esr-candidates/build1/linux-x86_64/en-US/firefox-45.6.0esr.checksums.asc
//
// set up Spidermonkey by unzipping it and adding it to your PATH and LD_LIBRARY_PATH:
// mkdir spidermonkey
// cd spidermonkey
// unzip ../jsshell-linux-x86_64.zip
@cosinusoidally
cosinusoidally / gist:16ad712d2659dbf4f65a1d823ae35fbd
Last active December 6, 2016 00:35
WIP setting up Emscripten in a Centos 6 proot
Tested on an Ubuntu 12.04 and Ubuntu 14.04 host:
We first need an CentOS 6 chroot. I wanted to do this without requring root on the host machine.
I order to do this I used a piece of software called PRoot https://github.com/proot-me/PRoot .
PRoot provides chroot emulation without requiring root. I does this by intercepting and modifying syscalls using ptrace.
You'll need libtalloc to build proot. Ubuntu has packages:
apt-get install libtalloc2 libtalloc-dev
w='Head|shoulders|knees and| toes|and eyes| and ears| and mouth and| nose|'.split('|');c=', ';n='\n';for(i=-1;++i<9;){k=w[2]+w[3]+n;f=w[0]+c+w[1]+c+k+k;console.log(f+f+w[4]+w[5]+w[6]+w[7]+n+f);w[i]=w[i].replace(/\w+/g,'...')}
x="...";
y=x+" "+x;
z=x+" "+x+" "+x;
r=[[/#/g,x],
[/Head/g,x],
[/shoulders/g,x],
[/knees and/g,y],
[/toes/g,x],
[/and eyes/g,y],
[/and ears/g,y],
@cosinusoidally
cosinusoidally / gist:1211111
Created September 12, 2011 12:06
vorbis esq public
fs=require("fs");
a=fs.openSync("a.raw","r");
var b=fs.openSync("c.raw","w");
off=0;
var sizeof=function(a){return a.length};
var assert=function(){};
var bit_reverse=function(n){