Skip to content

Instantly share code, notes, and snippets.

View LiamKarlMitchell's full-sized avatar

Liam Mitchell LiamKarlMitchell

View GitHub Profile
@khigia
khigia / NumericUpDown MouseWheel
Created October 16, 2009 01:57
C# NumericUpDown MouseWheel event
class MyNumericUpDown : NumericUpDown
{
protected override void OnMouseWheel (MouseEventArgs e)
{
// remove scrolllines scaling, taking care of case scrolllines is 0
int delta = e.Delta / Math.Max (Math.Abs (SystemInformation.MouseWheelScrollLines), 1);
base.OnMouseWheel (new MouseEventArgs (e.Button, e.Clicks, e.X, e.Y, delta));
}
}
@sindresorhus
sindresorhus / mysql-backup-windows.bat
Created March 14, 2011 14:50
Backup MySQL databases in separate gzipped sql files on Windows
@echo off
set dbUser=root
set dbPassword=password
set backupDir="C:\Documents and Settings\user\Desktop\backup\mysql"
set mysqldump="C:\Program Files\MySQL\MySQL Workbench 5.2 CE\mysqldump.exe"
set mysqlDataDir="C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.1\data"
set zip="C:\Program Files\7-Zip\7z.exe"
:: get date
@ShirtlessKirk
ShirtlessKirk / luhn.js
Last active May 17, 2024 08:05
Luhn validation algorithm
/**
* Luhn algorithm in JavaScript: validate credit card number supplied as string of numbers
* @author ShirtlessKirk. Copyright (c) 2012.
* @license WTFPL (http://www.wtfpl.net/txt/copying)
*/
var luhnChk = (function (arr) {
return function (ccNum) {
var
len = ccNum.length,
bit = 1,
@conorbuck
conorbuck / angle-between-points.js
Created May 5, 2012 22:51
JavaScript: Find the angle between two points
var p1 = {
x: 20,
y: 20
};
var p2 = {
x: 40,
y: 40
};
@balupton
balupton / cors.js
Created September 11, 2012 05:21
Acheiving CORS via a Node HTTP Server
// Create our server
var server;
server = http.createServer(function(req,res){
// Set CORS headers
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Request-Method', '*');
res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET');
res.setHeader('Access-Control-Allow-Headers', '*');
if ( req.method === 'OPTIONS' ) {
res.writeHead(200);
@x1nixmzeng
x1nixmzeng / prelen.bt
Last active July 31, 2021 20:43
Binary template for reading strings of known or unknown length
//--------------------------------------
//--- 010 Editor v5.0.0 Binary Template
//
// File: prelen.bt
// Author: x1nixmzeng/WRS
// Revision: v1.03
// Purpose: Reading strings of known length
// History
// v1.03 Added optional STR_ENCODING macro to specify the charset
// used to format the template results
@DiegoSalazar
DiegoSalazar / validate_credit_card.js
Last active April 24, 2024 12:51
Luhn algorithm in Javascript. Check valid credit card numbers
// Takes a credit card string value and returns true on valid number
function valid_credit_card(value) {
// Accept only digits, dashes or spaces
if (/[^0-9-\s]+/.test(value)) return false;
// The Luhn Algorithm. It's so pretty.
let nCheck = 0, bEven = false;
value = value.replace(/\D/g, "");
for (var n = value.length - 1; n >= 0; n--) {
@jvsidler
jvsidler / gist:4610255
Created January 23, 2013 17:14
List all crontabs for all users on UNIX systems. Must be root. Credit: http://stackoverflow.com/questions/134906/how-do-i-list-all-cron-jobs-for-all-users
for user in $(cut -f1 -d: /etc/passwd); do echo $user; crontab -u $user -l; done
@unsetbit
unsetbit / Quadtree
Created February 4, 2013 04:37
Near-infinitely scaling quadtree
/* Quadtree by Ozan Turgut (ozanturgut@gmail.com)
A Quadtree is a structure for managing many nodes interacting in space by
organizing them within a tree, where each node contains elements which may
interact with other elements within the node. This is particularly useful in
collision detection, in which a brute-force algorithm requires the checking of
every element against every other element, regardless of their distance in space.
This quadtree handles object in 2d space by their bounding boxes. It splits
a node once it exceeds the object limit per-node. When a node is split, it's
@DerMitch
DerMitch / autoreload_supervisor.sh
Created October 31, 2013 15:33
auto-reload supervisord config on changes
#!/bin/sh
# auto-reload supervisor config on a config file change
# Licensed under Public Domain
# apt-get install inotify-tools
while true; do
inotifywait --quiet --recursive --event create,close_write /etc/supervisor/
supervisorctl reread
supervisorctl update