Skip to content

Instantly share code, notes, and snippets.

View gheja's full-sized avatar
🤘

Gabor Heja gheja

🤘
View GitHub Profile
@kdzwinel
kdzwinel / trilateration.js
Created January 3, 2014 09:35
Simple trilateration algorithm implementation in JavaScript.
function getTrilateration(position1, position2, position3) {
var xa = position1.x;
var ya = position1.y;
var xb = position2.x;
var yb = position2.y;
var xc = position3.x;
var yc = position3.y;
var ra = position1.distance;
var rb = position2.distance;
var rc = position3.distance;
@raveren
raveren / cryptographically_secure_random_strings.php
Last active October 25, 2025 19:14
Generate cryptographically secure random strings. Based on Kohana's Text::random() method and this answer: http://stackoverflow.com/a/13733588/179104
function random_text( $type = 'alnum', $length = 8 )
{
switch ( $type ) {
case 'alnum':
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
case 'alpha':
$pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
case 'hexdec':
@mrluanma
mrluanma / datetime2stamp.py
Created July 6, 2012 02:21
Convert datetime to Unix timestamp.
def datetime2stamp(year, month, day, hour, minute, second):
timestamp = 0
for y in range(year - 1, 1969, -1):
if is_leap_year(y):
day += 366
else:
day += 365
month_day = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]