Skip to content

Instantly share code, notes, and snippets.

@xk
xk / threads.c
Last active May 2, 2017 14:49
8 cores 96MB buffers
// 2017-04-30 jorge@jorgechamorro.com
// See http://www.eevblog.com/forum/projects/in-search-of-a-supercomputer
#include <pthread.h>
#include <stdlib.h>
#define BUF_SIZE 96*1024*1024
pthread_t t1, t2, t3, t4, t5, t6, t7, t8;
double* nu_buffer () { return (double*) malloc(BUF_SIZE); }
@xk
xk / threads.c
Last active May 2, 2017 14:48
Another useless benchmark to illustrate a point
// 2017-04-30 jorge@jorgechamorro.com
// See http://www.eevblog.com/forum/projects/in-search-of-a-supercomputer
#include <pthread.h>
#include <stdlib.h>
#define BUF_SIZE 16*1024*1024
pthread_t t1, t2, t3, t4;
double* nu_buffer () { return (double*) malloc(BUF_SIZE); }
@xk
xk / batteryMon.sh
Last active January 31, 2017 16:11
kindle loop #1
sleep 1
# Apagar/parar cosas:
/etc/init.d/framework stop
/etc/init.d/powerd stop
/etc/init.d/pmond stop
killall webreader
# killall browserd NO VA NO SE POR QUÉ
killall browserd
killall tmd
@xk
xk / auto_wifi.sh
Last active January 13, 2017 18:35
WIFI AUTO RECONNECT
#!/bin/bash
# The IP for the server you wish to ping
SERVER=192.168.100.1
sleep 30s
while [ 1 ]; do
# Only send two pings, sending output to /dev/null
ping -c2 ${SERVER} > /dev/null
# If the return code from ping ($?) is not 0 (meaning there was an error)
@xk
xk / npm-debug.log
Created December 18, 2016 10:18
npm install node-gyp -g
root@opi1:~# cat npm-debug.log
0 info it worked if it ends with ok
1 verbose cli [ '/root/.nvm/v0.10.0/bin/node',
1 verbose cli '/root/.nvm/v0.10.0/bin/npm',
1 verbose cli 'install',
1 verbose cli 'node-gyp',
1 verbose cli '-g' ]
2 info using npm@1.2.14
3 info using node@v0.10.0
4 verbose read json /root/.nvm/v0.10.0/lib/package.json
@xk
xk / checktimers.js
Last active December 11, 2016 22:20
node.js timers are borken
// 2016-12-10 jorge@jorgechamorro.com
// node.js timers are borken: node checktimers.js errs all the time
// But this won't ever err in a browser: copy-paste in any browser's console
// Update: somewhere between node 0.10.26 and 0.12.0 this has been fixed
(function (ctr,flag,errors) {
function _1 () { flag= 0 }
function _2 () { errors+= flag }
function _3 () { flag= 1 }
@xk
xk / flutter.js
Last active December 10, 2016 12:34
JavaScript execution wow and flutter
// 2016-11-29 jorge@jorgechamorro.com
// JavaScript execution wow and flutter
var MAX_ms= -1;
var r, now, ctr, str;
var MAX_ctr= -1;
var MIN_ctr= 10e9;
function sync (now,r) {
now= Date.now()+ 1;
@xk
xk / buscarVariablesGlobales.js
Created November 5, 2015 13:09
Muestra las variables globales
(function buscarVariablesGlobales (dirtySet, cleanSet) {
//© 2013-02-19 jorge@jorgechamorro.com
dirtySet= document.body.appendChild(document.createElement('iframe'));
cleanSet= Object.getOwnPropertyNames(dirtySet.contentWindow);
dirtySet.parentNode.removeChild(dirtySet);
dirtySet= Object.getOwnPropertyNames(function () { return this }());
return dirtySet.filter(function (v,i,o) { return cleanSet.indexOf(v) < 0 });
})()
@xk
xk / blocks.js
Created March 10, 2014 20:21
Blocks === multiline
/*!
multiline
Multiline strings in JavaScript
https://github.com/sindresorhus/multiline
by Sindre Sorhus
MIT License
*/
(function () {
'use strict';
@xk
xk / brightness.c
Created February 11, 2014 22:02
Brightness.c
/* gcc -std=c99 -o brightness brightness.c -framework IOKit -framework ApplicationServices */
#include <stdio.h>
#include <unistd.h>
#include <IOKit/graphics/IOGraphicsLib.h>
#include <ApplicationServices/ApplicationServices.h>
const int kMaxDisplays = 16;
const CFStringRef kDisplayBrightness = CFSTR(kIODisplayBrightnessKey);
const char *APP_NAME;