Skip to content

Instantly share code, notes, and snippets.

View gheja's full-sized avatar
🤘

Gabor Heja gheja

🤘
View GitHub Profile
@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]
@raveren
raveren / cryptographically_secure_random_strings.php
Last active November 21, 2023 12:35
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':
@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;
@subzey
subzey / dson.js
Last active August 29, 2015 14:02
DSON shim
var DSON = DSON || {
parse: function(v) {
return JSON.parse(v.replace(/"(\\"|[^"])*"|[a-z]+/gi, function(v) {
return {
such: '{',
wow: '}',
is: ':',
so: '[',
many: ']',
next: ',',
@subzey
subzey / gist:b18c482922cd17693d65
Last active August 29, 2015 14:06
Few Tricks on Compressing Js13k Entry

Few Tricks on Compressing Js13k Entry

Most important detail: in js13k entry 13k stands for zipped entry size. And this detail makes js13k differ from other code golfing compos.

Last year winner entry uncompressed size was about 70k. 70 kilobytes! In js1k you have a month to minify 1k, so how much time would it take to minify 70k? Nope, you have only 1 month. So it's very unlikely one will manually golf the entry. And this is the other thing that makes js13k special: no hardcore manual "hell yeah I've stripped one byte!" golfing.

@xem
xem / readme.md
Last active July 14, 2024 10:15
Maths & trigonometry cheat sheet for 2D & 3D games

Conventions

  • A = [xA, yA] is a point on the 2D plane. Same for B, C, ...
  • lengths are in any unit (ex: pixels)
  • code snippets are in JavaScript

Degrees to radians

angleRad = angleDeg * Math.PI / 180;

@stecman
stecman / Makefile
Last active June 27, 2024 20:48
DS18B20 1-Wire implementation for Atmel AVR
DEVICE = atmega328p
CLOCK = 16000000
PROGRAMMER = -c arduino -P /dev/ttyUSB0 -b57600
AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE)
SOURCES = $(shell find . -name '*.c')
OBJECTS = $(SOURCES:.c=.o)
# Automatic dependency resolution
from math import *
# a performant solution would store a prefix sum of line lengths to
# a sidechannel and then use that to do a bsearch; on the GPU,
# you'd do a sum tree / histopyramid as a preprocessing step
def find_point(points, d):
d = d
for i in range(1, len(points)):
x0,y0 = points[i-1]
x1,y1 = points[i]
@marcan
marcan / rpi_cam_auth.py
Created January 25, 2019 07:48
Raspberry Pi Camera V2 DRM authentication example
import hmac, hashlib
# Data from I²C trace at https://hackaday.io/project/19480-raspberry-pi-camera-v21-reversed/log/52547-i2c-logic-analyzer-trace
# Secret key from VideoCore blob
# serial[8], serial[7:4], serial[3:0]
serial = bytes.fromhex("EE8C196D8301230B59")
# rPi -> camera random number
numIn = bytes.fromhex("5805F3C898C3133154498E082F2E703516F2DBD1")
RSA Private-Key: (6969 bit, 69 primes)
modulus:
01:01:57:5a:5e:73:6f:8f:02:77:e3:27:6e:c6:bd:
97:cf:32:95:de:59:a7:32:7e:64:84:e3:3e:e8:17:
f3:8c:07:5c:1e:74:7a:40:33:86:7b:45:bc:e0:b6:
c8:6c:e3:fa:5a:1c:65:18:1a:5c:fc:3c:8a:c4:f5:
6f:63:60:32:cc:cd:03:b5:c9:54:29:d5:b2:c1:24:
54:81:0b:f4:40:53:84:e5:14:2c:58:70:98:7f:36:
6b:ef:df:13:5e:8f:07:05:f1:42:25:cf:30:82:94:
9a:11:df:49:9a:76:51:ad:6e:d7:46:2d:b8:ed:39: