Skip to content

Instantly share code, notes, and snippets.

View lukespragg's full-sized avatar

Luke Spragg lukespragg

View GitHub Profile
GetUtcOffSet - JsonConvert.cs Line 111
private static TimeSpan GetUtcOffset(DateTime dateTime)
{
#if SILVERLIGHT
return TimeZoneInfo.Local.GetUtcOffset(dateTime);
#else
return TimeZone.CurrentTimeZone.GetUtcOffset(dateTime);
#endif
}
@lukespragg
lukespragg / sha256.lua
Created July 31, 2015 02:06
Lua SHA256
local mod = 2^32
local modm = mod-1
local function memoize(f)
local mt = {}
local t = setmetatable({}, mt)
function mt:__index(k)
local v = f(k)
t[k] = v
return v
@lukespragg
lukespragg / base64.lua
Created July 31, 2015 02:05
Lua 5.1+ base64 v3.0 (c) 2009 by Alex Kloss <alexthkloss@web.de> Licensed under the terms of the LGPL2
local function base64(data)
-- Lua 5.1+ base64 v3.0 (c) 2009 by Alex Kloss <alexthkloss@web.de>
-- Licensed under the terms of the LGPL2
local b = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
return ((data:gsub('.', function(x)
local r, b = '', x:byte()
for i = 8, 1, -1 do r = r .. (b % 2 ^ i - b % 2 ^ (i - 1) > 0 and '1' or '0') end
return r;
end) .. '0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
@lukespragg
lukespragg / envpath.bat
Created December 19, 2014 16:27
Add environmental path via Windows Registry
reg add HKCU\Environment /v SERVERS /t REG_EXPAND_SZ /d "D:\Servers" /f
{
"Settings": {
"ChatName": "FOO",
"ChatCommand": "bar",
"DoSomething": "false",
"ThisNumber": 50
},
"Messages": {
"HelloWorld": "This is a message"
}
@lukespragg
lukespragg / meme.php
Created October 4, 2014 06:00
Unfinished meme generator that was actually meant for something else, but is just scrap now...
<?php
// Set the content-type
header ("Content-type: image/jpeg");
// Get text from URL
$text = $_GET['text'];
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
@lukespragg
lukespragg / proxy-settings.vbs
Created September 27, 2014 23:59
Internet Explorer and Firefox proxy settings script.
use strict;
use Win32::TieRegistry ( Delimiter=>"/", ArrayValues=>1 );
&setProxy();
###############
sub setProxy{
#Set access to use proxy server (IE)
#http://nscsysop.hypermart.net/setproxy.html
my $server=shift || "localhost";
my $port=shift || 8080;
my $enable=shift || 1;
@lukespragg
lukespragg / update-gh-pages.sh
Created September 27, 2014 23:45
Basic script for updating GitHub pages from Travis-CI.
if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
echo -e "Changing directory to $HOME and configuring git"
cd $HOME
git config --global user.email "travis@travis-ci.org"
git config --global user.name "Travis"
echo -e "Cloning gh-pages repo using token"
git clone --quiet --branch=gh-pages https://$GH_TOKEN@github.com/$TRAVIS_REPO_SLUG.git gh-pages > /dev/null
echo -e "Copy apidocs to gh-pages repo root"
@lukespragg
lukespragg / developer-vows.php
Last active August 29, 2022 02:27
Developer wedding vows in PHP
<?php
function do_wed() {
if ($objections != true) {
function do_vow() {
$vow = 1;
do {
if ($richer === 1
&& $poorer === 1
&& $sickness === 1
&& $health === 1) {
@lukespragg
lukespragg / server-backup.sh
Created September 17, 2014 19:51
Old, basic server backup script
#!/bin/sh
BACKUP_PATH=/home/USERNAME/backups/servers
SERVERS_HOME=/home/USERNAME/servers
mkdir -vp $BACKUP_PATH/game/minecraft/`date '+%Y%m%d'`
tar czvf $BACKUP_PATH/game/minecraft/demo/`date '+%Y%m%d'`.tgz $SERVERS_HOME/game/minecraft/demo
tar czvf $BACKUP_PATH/game/minecraft/dev/`date '+%Y%m%d'`.tgz $SERVERS_HOME/game/minecraft/dev
#mkdir -vp $BACKUP_PATH/voice/mumble