Skip to content

Instantly share code, notes, and snippets.

View ROBERT-MCDOWELL's full-sized avatar

ROBERT MCDOWELL ROBERT-MCDOWELL

View GitHub Profile
@fliptopbox
fliptopbox / string.compress.js
Created October 15, 2013 12:32
JavaScript String compression
/*
@fliptopbox
LZW Compression/Decompression for Strings
Implementation of LZW algorithms from:
http://rosettacode.org/wiki/LZW_compression#JavaScript
Usage:
var a = 'a very very long string to be squashed';
var b = a.compress(); // 'a veryāăąlong striċ to bečquashed'
@fetus-hina
fetus-hina / weeknumber2date.php
Created November 23, 2012 10:44
Calculate date by ISO-Week-Number (and wday)
<?php
function weekNumberToDate($year, $week, $wday = 1) {
// http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
$correction = (int)gmdate('w', gmmktime(0, 0, 0, 1, 4, (int)$year)) + 3;
$yday = (int)$week * 7 + (int)$wday - $correction;
$time = gmmktime(0, 0, 0, 1, $yday, (int)$year);
return array((int)gmdate('Y', $time), (int)gmdate('n', $time), (int)gmdate('j', $time));
}
var_dump(weekNumberToDate(2008, 39, 6));
@apk
apk / websock.sh
Created April 18, 2012 15:51
A web socket server as a bash script.
#!/bin/bash
# WebSocket shell, start & browse to http://<Host>:6655/
# Requires bash 4.x, openssl.
# Author: [email protected] (which isn't me, apk)
coproc d { nc -l -p 6656 -q 0; }
nc -l -p 6655 -q 1 > /dev/null <<-ENDOFPAGE
HTTP/1.1 200 OK
<html><head><script language="javascript">
var url = location.hostname + ':' + (parseInt(location.port) + 1);