Skip to content

Instantly share code, notes, and snippets.

View scarvell's full-sized avatar

Brendan Scarvell scarvell

View GitHub Profile
@scarvell
scarvell / mobile_check.php
Created March 25, 2012 10:20
Detects if visitor is using a mobile device
<?php
function isMobileBrowser()
{
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$mobileBrowser = false;
// iPhone check
if( eregi('ipod',$user_agent)|| eregi('iphone',$user_agent) )
{
@scarvell
scarvell / ratings.php
Created May 13, 2012 00:36
PVP Ratings Algo
<?php
$teamA = 2000;
$teamB = 2280;
// If over 2000 rating, lower point cap
$maxPt = ($teamA >= 2000 && $teamB >= 2000) ? 18 : 32; // Max points
$teamApc = 1 / ( 1+pow(10,($teamB - $teamA)/400));
$teamBpc = 1 / ( 1+pow(10, ($teamA - $teamB)/400));
@scarvell
scarvell / handbrake cli
Created July 16, 2012 23:31
handbrake encode
#!/usr/bin/env coffee
spawn = require('child_process').spawn
fs = require 'fs'
argv = require('optimist').argv
path = require 'path'
if !argv.dir?
console.log 'USAGE: ./encode.coffee --dir=DIR'
return
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
margin: 0;
var i;
for (i = 0; i < 100; i++) {
if (i % 15 == 0 )
console.log("FizzBuzz"); // Divisible by 3 and 5
else if (i % 3 == 0)
console.log("Fizz");
else if (i % 5 == 0)
console.log("Buzz");
else
@scarvell
scarvell / stream_upload.js
Last active December 14, 2015 04:39
nodejs stream file upload
var http = require('http')
, fs = require('fs');
http.createServer(function(req, res){
var newFile = fs.createWriteStream("myfile.md");
var fileBytes = req.headers['content-length'];
var uploadedBytes = 0;
req.pipe(newFile);
@scarvell
scarvell / dominant rgb.vb
Created March 5, 2013 02:20
Color Hot-Track
Function AverageRGB(ByRef P As PictureBox) As Long
Dim Count As Long
Dim Red As Long
Dim Green As Long
Dim Blue As Long
Dim Hexed As String
Dim X As Long
Dim Y As Long
Count = 0
@scarvell
scarvell / gist:5408280
Created April 17, 2013 22:26
wtf regex
(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t]
)+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:
\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(
?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[
\t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\0
31]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\
](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+
(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:
(?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z
|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)
@scarvell
scarvell / cookie.js
Last active December 17, 2015 13:29
@scarvell
scarvell / sqli.regex
Last active December 23, 2015 17:09
JSTL/EL regex to detect SQL injections
((where|set).* (like|=|>|<|in\s?\(?)\s?["']?\%?\$\{|IN\s?\(.*\$\{)