Skip to content

Instantly share code, notes, and snippets.

@banksean
banksean / mersenne-twister.js
Created February 10, 2010 16:24
a Mersenne Twister implementation in javascript. Makes up for Math.random() not letting you specify a seed value.
/*
I've wrapped Makoto Matsumoto and Takuji Nishimura's code in a namespace
so it's better encapsulated. Now you can have multiple random number generators
and they won't stomp all over eachother's state.
If you want to use this as a substitute for Math.random(), use the random()
method like so:
var m = new MersenneTwister();
@beniwohli
beniwohli / unicode_to_latex.py
Created January 27, 2011 14:08
Map to convert unicode characters to their respective LaTeX representation
# original XML at http://www.w3.org/Math/characters/unicode.xml
# XSL for conversion: https://gist.github.com/798546
unicode_to_latex = {
u"\u0020": "\\space ",
u"\u0023": "\\#",
u"\u0024": "\\textdollar ",
u"\u0025": "\\%",
u"\u0026": "\\&",
@vsajip
vsajip / deleghand.py
Created January 16, 2012 23:53
Example of a delegating handler
import logging
import random
import re
class DelegatingHandler(logging.Handler):
def __init__(self, *handlers):
logging.Handler.__init__(self)
self.handlers = handlers
@pmahoney
pmahoney / gist:1970815
Created March 4, 2012 05:28
Jenkins and Java fork()+exec() out of memory

Orien is correct, it is the fork() system call triggered by ProcessBuilder or Runtime.exec or other means of the JVM executing an external process (e.g. another JVM running ant, a git command, etc.).

There have been some posts on the Jenkins mailing lists about this: Cannot run program "git" ... error=12, Cannot allocate memory

There is a nice description of the issue on the SCons dev list: fork()+exec() vs posix_spawn()

There is a long standing JVM bug report with solutions: Use posix_spawn, not fork, on S10 to avoid swap exhaustion. But I'm not sure if this actually made it into JDK7 as the comments suggest was the plan.

In summary, on Unix-like systems, when one process (e.g. the JVM) needs to launch another process (e.g. git) a system call is made to

@janogarcia
janogarcia / php_valid_twitter_hashtag_regex.php
Created October 24, 2012 15:01
PHP Twitter Hashtag Validation Regex
<?php
/**
* PHP Regex to validate a Twitter hashtag
*
* Useful for validating a text input (an HTML form in your CMS or custom application) that must be a valid Twitter hashtag.
* Valid examples: #a, #_, #_1, #_a, #1a, #áéìôü, #123hàsh_täg446
* Invalid examples: #1, ##hashtag, #hash-tag, #hash.tag, #hash tag, #hashtag!, (any hashtag that is more than 140 characters long, hash symbol included)
*
* Regex explanation:
* First, the lookahead assertion (?=.{2,140}$) checks the minimum and max length, as explained here http://stackoverflow.com/a/4223213/1441613
@urschrei
urschrei / basemap_descartes.py
Last active November 6, 2020 02:49
How to plot Shapely Points using Matplotlib, Basemap, and Descartes
"""
required packages:
numpy
matplotlib
basemap: http://matplotlib.org/basemap/users/installing.html
shapely: https://pypi.python.org/pypi/Shapely
descartes: https://pypi.python.org/pypi/descartes
random
@Autoplectic
Autoplectic / pre-commit
Last active December 26, 2015 02:29
A git pre-commit hook to run tests and pylint prior to a commit, and fail if any tests fail.
#!/usr/bin/env python
###############################################################################
# Ryan James
"""
This pre-commit hook runs nosetests and pylint, reporting their scores.
It blocks commits with failing tests.
To install
----------
@mbostock
mbostock / .block
Last active September 21, 2023 03:14
Cubehelix II
license: gpl-3.0
@nigelmcnie
nigelmcnie / gist:ae856b5804fa9713f54e
Last active August 29, 2015 14:07
Quantum datetime library for python - demo
# Create a quantum, which represents an exact point in time. Internally, the point of time is stored
# as UTC
> t1 = quantum.now()
<Quantum(2014-10-01 20:23:57.745648, no timezone)>
# We can ask for that point of time "at" a certain timezone. Relevant for datemath and display
> t1.at('Pacific/Auckland')
<Quantum(2014-10-01 20:23:57.745648, Pacific/Auckland)>
# We can get a naive datetime out of it at any TZ
@sanchezzzhak
sanchezzzhak / clickhouse-get-tables-size.sql
Created January 18, 2018 13:43
clickhouse get tables size
SELECT table,
formatReadableSize(sum(bytes)) as size,
min(min_date) as min_date,
max(max_date) as max_date
FROM system.parts
WHERE active
GROUP BY table