Skip to content

Instantly share code, notes, and snippets.

Alright then, lets start with copy array a into b, by reusing and modifying memset.

function memcpy(dst, src, size) {
  for (var i = 0; i < size; ++i) {
    dst[i] = src[i];
  }
} 

Now, thats nice, but does not actually make sure that the arrays have the same CType, better add a check for that.

var x11 = require('x11');
var PNG = require('png-js');
var bl = require('bl');
require('child_process').exec('locate png | grep 48').stdout.pipe(bl(function(err, files) {
var pngNames = files.toString().split('\n');
var pngIndex = 0;
x11.createClient(function(err, display) {
@alex-spataru
alex-spataru / Opening files using system events in Qt
Last active August 29, 2015 14:14
Open files from system request on Mac [Qt]
#include <QEvent>
#include <QApplication>
// Create a subclass of QApplication so that we can customize what we
// do when the operating system sends us an event (such as opening a file)
class MyApp : public QApplication
{
Q_OBJECT
@Noitidart
Noitidart / _ff-addon-snippet-X11_XGetWindowProperty.js
Last active August 29, 2015 14:16
_ff-addon-snippet-X11_XGetWindowProperty - Shows how to use XGetWindowProperty, this is my skeleton for when I use it. [jsctypes] [x11] [unix]
Cu.import('resource://gre/modules/ctypes.jsm');
var nixtypesInit = function() {
// BASIC TYPES (ones that arent equal to something predefined by me)
this.ATOM = ctypes.unsigned_long;
this.BOOL = ctypes.int;
this.CHAR = ctypes.char;
this.GDKDRAWABLE = ctypes.StructType('GdkDrawable');
this.GDKWINDOW = ctypes.StructType('GdkWindow');
this.DATA = ctypes.voidptr_t;
@Yoric
Yoric / gist:c710b97dd55f98f8f0e3
Created April 20, 2015 09:52
Making a PromiseWorker that can shutdown
let myWorker = {
//
// Worker initialization
//
get worker() {
if (this._worker) {
return this._worker;
}
// Otherwise, initialize PromiseWorker.
// TODO
@luckyrat
luckyrat / gist:7803415810fb4c09c975
Created May 22, 2015 11:08
importGlobalProperties test JSM
// JSM for working out which globalproperties can be imported in a specific Firefox version.
// https://developer.mozilla.org/en-US/docs/Components.utils.importGlobalProperties
// I'm not certain availability always equates to functionality but it probably does
// and in any case it's a way to narrow down the more involved test for functionality of each property
// Run from browser toolbox scratchpad like:
// Components.utils.import("resource://test-importGlobalProperties-addon/test.jsm");
Components.utils.import("resource://gre/modules/devtools/Console.jsm");
@kewisch
kewisch / TracedRequest.js
Created October 2, 2014 14:20
Monitor all http(s) network requests using the Mozilla Platform
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var allRequests = [];
/**
* Add the following function as a request observer:
* Services.obs.addObserver(httpObserver, "http-on-examine-response", false);
*
@milin
milin / django.test.client import proble,
Created January 28, 2011 18:09
django.test.client import Client gives django_settings_module not specified problem
import django
import httplib2
import time,urlparse,urllib
from django.conf import settings
import oauth2 as oauth
from django.test.client import Client
@piroor
piroor / crash-with-crashreport.js
Last active December 31, 2015 14:49
Crash firefox by js-ctypes (run in the scratch pad or the browser console)
(function(){
Components.utils.import('resource://gre/modules/ctypes.jsm');
var library = ctypes.open(ctypes.libraryName('nss3'));
var PR_Free = library.declare(
'PR_Free',
ctypes.default_abi,
ctypes.void_t,
ctypes.voidptr_t
);
var ptr = new ctypes.voidptr_t(0123);