Skip to content

Instantly share code, notes, and snippets.

@dvberkel
dvberkel / gist:1950267
Created March 1, 2012 14:53
Duvals Algorithm for generating Lyndon words
"""Lyndon.py
Algorithms on strings and sequences based on Lyndon words.
David Eppstein, October 2011."""
import unittest
from Eratosthenes import MoebiusFunction
def LengthLimitedLyndonWords(s,n):
"""Generate nonempty Lyndon words of length <= n over an s-symbol alphabet.
The words are generated in lexicographic order, using an algorithm from
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@jboner
jboner / latency.txt
Last active May 19, 2024 16:30
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@kravchik
kravchik / Executor.java
Created June 20, 2012 20:26
Primitively simple lisp implementation
package simple;
import par.ParParser;
import java.util.List;
import java.util.Map;
import static yk.Util.copy;
import static yk.Util.list;
import static yk.Util.map;
@rygorous
rygorous / magic_ring.cpp
Created July 22, 2012 03:55
The magic ring buffer.
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <string.h>
#include <Windows.h>
// This allocates a "magic ring buffer" that is mapped twice, with the two
// copies being contiguous in (virtual) memory. The advantage of this is
// that this allows any function that expects data to be contiguous in
// memory to read from (or write to) such a buffer. It also means that
@mericson
mericson / loadUrl.jsx
Created September 10, 2013 14:13
Loads data from a URL in Adobe Illustrator! (Uses Bridge behind the scenes)
var doc = app.activeDocument;
var docPath = doc.path;
function loadUrl(url, callback) {
var bt = new BridgeTalk();
bt.target = 'bridge' ;
@jo
jo / js-crypto-libraries.md
Last active March 31, 2024 20:33
List of JavaScript Crypto libraries.

JavaScript Crypto Libraries

List some crypto libraries for JavaScript out there. Might be a bit out dated. Scroll to the bottom.

WebCryptoAPI

http://www.w3.org/TR/WebCryptoAPI/

This specification describes a JavaScript API for performing basic cryptographic operations in web applications, such as hashing, signature generation and verification, and encryption and decryption. Additionally, it describes an API for applications to generate and/or manage the keying material necessary to perform these operations. Uses for this API range from user or service authentication, document or code signing, and the confidentiality and integrity of communications.

/**
* Cycle detection function
* Outputs count and grouped cycles with a from key path and to key path.
* The executing browser should have console.group and .groupEnd functions.
*
* Based on:
* http://stackoverflow.com/questions/14962018/detecting-and-fixing-circular-references-in-javascript/14962496#14962496
*
* @param {Object} obj Any js object
* @return {void}
Below I collected relevant links and papers more or less pertaining to the subject of tetrahedral meshes.
It's an ever-growing list.
------------------------------
Relevant links:
http://en.wikipedia.org/wiki/Types_of_mesh
http://en.wikipedia.org/wiki/Tetrahedron
http://en.wikipedia.org/wiki/Simplicial_complex
@ihnorton
ihnorton / ex.cs
Last active November 30, 2023 19:52
Simple example of calling Julia from C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Program