Skip to content

Instantly share code, notes, and snippets.

@milani
milani / advanced_collision_detection.js
Created March 16, 2011 21:15
Collision detection with javascript using interval tree
// Collision detection with javascript using semi-interval tree.
// Add elements using insert function, then check collision using hasCollision.
var collisionTree = {
LEFT: 1,
RIGHT: 0,
INTERSECT: 2,
nodes:null,
margin: 1,
init: function(margin){
this.nodes = new Array();
function formatTag(tag){
var elements = $('content').getElementsBySelector(tag);
elements.forEach(function(P,index){
// calculate frequency of characters for the first few characters ( 30 )
var charCode,
arabicFreq = 0,
englishFreq = 0,
length = 30,
parentDir = $(P).getStyle('direction'),
text = P.innerText;
@milani
milani / node_gui_webkit_view.cc
Created March 27, 2012 01:41
buggy Webkit widget for node-gui
#include <webkit/webkit.h>
#include "node_gui_webkit_view.h"
namespace clip {
Persistent<FunctionTemplate> WebkitView::constructor_template;
void WebkitView::Init (Handle<v8::Object> target) {
ATTACH_CONSTRUCTOR("WebkitView", WebkitView, (Constructor<WebkitView, webkit_web_view_get_type>));
ATTACH_INHERITANCE(Container);
var app = express.createServer();
var publicPath = './public';
var adminPath = './admin';
app.use(express.static( path.resolve( publicPath ) ) );
app.use(function(req,res,next){
// if req.path starts with /admin/ and user is logged in call next
// else redirect to login page
8.7M ./Contents/MacOS
4.0K ./Contents/Resources/am.lproj
4.0K ./Contents/Resources/app
4.0K ./Contents/Resources/ar.lproj
4.0K ./Contents/Resources/bg.lproj
20K ./Contents/Resources/blackberry
8.0K ./Contents/Resources/bn.lproj
4.0K ./Contents/Resources/ca.lproj
4.0K ./Contents/Resources/cs.lproj
4.0K ./Contents/Resources/da.lproj
@milani
milani / gist:3434679
Created August 23, 2012 09:34
Best way to convert an accept type object to equv. string
Best way to convert acceptType object to a string like below?
From:
var acceptTypes = {
'Images': ['*.png','*.jpg'],
'Documents': ['*.docx']
}
To:
var acceptType = 'Images:*.png,*.jpg;Documents:*.docx'
var spawn = require('child_process').spawn;
worker = spawn('node',['worker.js']);
worker.stdout.on('data',function(data){
console.log('worker sent:',data.toString());
});
console.log("Hello World Gist Runner!");
var fs = require('fs')
, buff = new Buffer(1500)
, fd = fs.openSync('/var/log/radius/radacct.log','r')
, position = fs.fstatSync(fd).size;
fs.read(fd,buff,0,1,position - 1,function(err,bytesRead,buffer){
if(err) {
return console.log('err');
}
@milani
milani / test-repeat-elements.py
Created July 30, 2017 05:30
Tests different repeat-elements implementations in tensorflow for Keras
import tensorflow as tf [8/15095]
import numpy as np
import timeit
def concatenate(tensors,axis=-1):
return tf.concat([x for x in tensors], axis)
def repeat_elements_original(x, rep, axis):
x_shape = x.get_shape().as_list()
# slices along the repeat axis