Skip to content

Instantly share code, notes, and snippets.

View carbonphyber's full-sized avatar

David Wortham carbonphyber

View GitHub Profile
@carbonphyber
carbonphyber / isPalendrome.rb
Created April 30, 2011 17:59
Ruby function to detect if a Fixednum is a palendrome.
# @author David Wortham <djwortham+programming@gmail.com>
# @date 2011-04-30
# @license MIT License: http://www.opensource.org/licenses/mit-license.php
def isPalendrome(number)
numberStr = number.to_s()
return false if numberStr.empty? || numberStr.length < 0
return true if numberStr.length < 2
lCursor = 0
rCursor = numberStr.length - 1
@carbonphyber
carbonphyber / factorize.rb
Created April 30, 2011 19:23
Ruby function to detect the factors of a Fixednum.
# @author David Wortham <djwortham+programming@gmail.com>
# @date 2011-04-30
# @license MIT License: http://www.opensource.org/licenses/mit-license.php
def factorize(input)
remainingInput = input
factors = {}
i = 2
while i <= remainingInput
while remainingInput % i == 0
@carbonphyber
carbonphyber / isPrime.rb
Created April 30, 2011 20:19
Ruby function to detect if a Fixednum is a prime number
# @author David Wortham <djwortham+programming@gmail.com>
# @date 2011-04-30
# @license MIT License: http://www.opensource.org/licenses/mit-license.php
# isPrime
# Function to detect if the input (asserted Fixednum) is a prime number
# uses an optional cache (asserted Hash) to speed up subsequent calls
def isPrime(number, cache)
return false if number < 1
return true if number == 1
@carbonphyber
carbonphyber / pre-commit
Created June 6, 2011 21:53
Git pre-commit hook for PHP+JS+CSS (Gaia version)
#!/usr/bin/env php
<?php
$output = array();
$errorOutput = array();
$return = 0;
$pathToErrorFile = 'temp/minify_errors.txt';
file_put_contents($pathToErrorFile, '');
exec('git rev-parse --verify HEAD 2> /dev/null', $output, $return);
$against = $return == 0 ? 'HEAD' : '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
@carbonphyber
carbonphyber / bbcode.php
Last active March 31, 2021 05:36
BBCode parser replacement candidate for GaiaOnline
<?php
/**
* \DJW\BBCode
* A BBCode translation class
* Uses OWASP cheatsheet to prevent XSS
* @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
*
* @author CarbonPhyber
*/
namespace DJW;
@carbonphyber
carbonphyber / all_tests.php
Last active March 31, 2021 05:35
Unit tests for new BBCode Parser
<?php
/**
* Unit Tests for BBCode parser
* Uses OWASP cheatsheet to prevent XSS
* @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
*
* @author CarbonPhyber
*/
require dirname(dirname(dirname(__FILE__))) . '/private/common.php';
package main
import (
"net/http"
"./muxtester" // this is our router library. the "muxtester" dir should be in the same directory as this "main.go"
)
func main() {
http.HandleFunc("/", muxtester.HandleCatchall)
http.ListenAndServe("localhost:8080", nil)
@carbonphyber
carbonphyber / currency_to_float.js
Last active August 29, 2015 14:26
A function to parse a USD currency
"use strict";
var tests = {
"$0.41": 0.41,
"$12,345.67": 12345.67,
"$1m": 1000000,
"$32b": 32000000000,
"$0.2t": 200000000000
};
@carbonphyber
carbonphyber / index.ios.js
Last active October 13, 2015 20:08
Modified Sample1 of React-Native-Webview-Bridge to reproduce exception thrown when unloaded via a React Native Navigator
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
var React = require('react-native');
var WebViewBridgeNative = require('react-native-webview-bridge');
var {
alert('xss!');