Skip to content

Instantly share code, notes, and snippets.

View louismullie's full-sized avatar

L louismullie

View GitHub Profile
@louismullie
louismullie / watershed-cuda.cu
Created December 14, 2012 23:04
CUDA watershed transform.
#define INF 9999999999
#define PLATEAU 0
#define BLOCK_SIZE 6
// Convert 2D index to 1D index.
#define INDEX(j,i,ld) ((j) * ld + (i))
// Convert local (shared memory) coord to global (image) coordinate.
#define L2I(ind,off) (((ind) / BLOCK_SIZE) * (BLOCK_SIZE - 2)-1+(off))
@louismullie
louismullie / java-6-7-switch.sh
Created December 28, 2012 03:19
Switching Between Java 6 and Java 7 on Mac OS X
$ /usr/libexec/java_home -v '1.6*'
=> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
$ export JAVA_HOME="/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home"
$ java -version
=> java version "1.6.0_37"
=> Java(TM) SE Runtime Environment (build 1.6.0_37-b06-434-11M3909)
=> Java HotSpot(TM) 64-Bit Server VM (build 20.12-b01-434, mixed mode)
@louismullie
louismullie / textrank-sentence.rb
Last active September 13, 2022 07:02
An implementation of the TextRank algorithm for extractive summarization using Treat + GraphRank. Uses the number of non-stop-words with a common stem as a similarity metric between sentences.
require 'graph-rank'
require 'treat'
# Implements the PageRank algorithm for
# unsupervised extractive summarization.
#
# Reference: R. Mihalcea and P. Tarau, “TextRank:
# Bringing Order into Texts,” in Proceedings of
# EMNLP 2004. Association for Computational
# Linguistics, 2004, pp. 404–411.
@louismullie
louismullie / gist:5320246
Created April 5, 2013 15:34
Testing WebWorkers.
//
BigInteger.prototype.toUByteArray = function (length) {
var bytes = this.toByteArray();
if (bytes.length == length + 1 && bytes[0] == 0)
bytes.shift();
return bytes;
};
salt: "883c4998"
A: "da4cf6bd34de1311ae3b112073e46b6cfd9fa5fd08eb64637b270a737bb4893440d320188eb40a74561fc0e007c56629c2ad3e3ad6f7438fe7659dddbebd30c403bf53d1fbc07cf6a876df9af3b08b425283bc4c9e42b544a83825cae6831760cc25f6b00129082c231f6b8577d7cd9a883102e163b24a18640435c35ca80d1f"
B: "5189bc826ba7c7c5fe727adee944f0883f23c3bedd93b94ccb3dd85b1256d3166948c04e77ed56506e50d609c684b4958e0147a435635c8d4e7286d16f0b20c43bf8378447912135377a8a9ddc84eae922b90193822aaf3cb5450ce2d60aefbd0a82fc277962d2ea82ca33da2bbf88755bc8f4fc7327b990f5b7daa9159094ff"
V: "852d1e42f4108cabb5fd47d9e0222487c5fea9deab76ae5ea8ab1263191d2a2c40be4f58669994da9ea762391bac6ba66f837bf3ef03d077fa4257703deb4fed914e7e6b47e02b73d4edc629370ce3926d8bbc6d52b06a39970b22a53aafb8f5c7fb16f4a4b06ed96a8608549a120d0f6c20b8ee1ff865aa477614bff9b8bc5a"
@louismullie
louismullie / encrypted-ajax.js
Last active March 25, 2019 16:18
Encrypted AJAX wrapper for jQuery.
var key = 'password';
$.encAjax = function (url, options) {
options.data = options.data || {};
var data = JSON.stringify(options.data);
var encryptedData = sjcl.encrypt(key, data);
# Results:
# +------------+--------------+------------+
# | Type | Uncompressed | Compressed |
# +------------+--------------+------------+
# | Plaintext | 649779 | 251901 |
# | Ciphertext | 649792 | 625780 |
# +------------+--------------+------------+
require 'openssl'
{
"iv": "Tbn0mZxQcroWnq4g/Pm+Gg",
"v": 1,
"iter": 1000,
"ks": 128,
"ts": 64,
"mode": "ccm",
"adata": "",
"cipher": "aes",
"salt": "pMQh7m9Scds",
@louismullie
louismullie / gist:6276540
Created August 20, 2013 02:37
Javascript - element in viewport
elementInViewport: function(el){
var r, html;
if ( !el || 1 !== el.nodeType ) { return false; }
html = document.documentElement;
r = el.getBoundingClientRect();
return ( !!r
&& r.bottom >= 0
&& r.right >= 0