Skip to content

Instantly share code, notes, and snippets.

View brandon-barker's full-sized avatar

Brandon Barker brandon-barker

  • Cape Town, South Africa
View GitHub Profile
Verifying my Blockstack ID is secured with the address 16ZPYPPyVVBAiACAc84BszA9L2TFyhhtX4 https://explorer.blockstack.org/address/16ZPYPPyVVBAiACAc84BszA9L2TFyhhtX4
@brandon-barker
brandon-barker / TakeAlot Saving Calculator.tamper.js
Created August 12, 2014 14:50
Saving calculator for takealot.com
// ==UserScript==
// @name TakeAlot Saving Calculator
// @namespace http://www.takealot.com/
// @version 0.1
// @description Shows % Saving on takealot.com
// @match http://www.takealot.com/*
// @copyright 2013, Brandon Barker
// ==/UserScript==
$('.price').each(function (key, value) {
@brandon-barker
brandon-barker / summary.js
Created March 5, 2014 20:53
Connect to sgminer API and return a summary using node-xgminer - https://www.npmjs.org/package/xgminer
var xgminer = require('../lib/xgminer');
var MinerAPI = new xgminer('Miner 1', '192.168.0.111', 4028);
MinerAPI.send('summary', '').then(function (res) {
console.log(res);
}, function (err) {
console.log(err);
});
@brandon-barker
brandon-barker / NotNullExtension.cs
Created February 27, 2014 20:28
An extension method for checking if an object is null
public static class NotNullExtension
{
public static TResult IfNotNull<TSource, TResult>(this TSource source, Func<TSource, TResult> accessor, TResult @default = default(TResult))
where TSource : class
{
return source != null
? accessor(source)
: @default;
}
}
var exec = require('child_process').exec,
child;
child = exec('cat *.js bad_file | wc -l',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
BitnetClient bc = new BitnetClient("http://127.0.0.1:8332");
bc.Credentials = new NetworkCredential("user", "pass");
 
var p = bc.GetDifficulty();
Console.WriteLine("Difficulty:" + p.ToString());
 
var inf = bc.GetInfo();
Console.WriteLine("Balance:" + inf["balance"]);
$(function() {
// Taken from http://stackoverflow.com/questions/17257237/decode-mixed-ascii-codes-from-a-string-in-javascript
function decodeHtmlNumeric( str ) {
return str.replace( /&#([0-9]{1,7});/g, function( g, m1 ){
return String.fromCharCode( parseInt( m1, 10 ) );
}).replace( /&#[xX]([0-9a-fA-F]{1,6});/g, function( g, m1 ){
return String.fromCharCode( parseInt( m1, 16 ) );
});
}
@brandon-barker
brandon-barker / app.js
Created September 2, 2013 19:56
socket.io event listeners
io.sockets.on('connection', function (socket) {
socket.on('addPlayer', function(player) {
players[socket.id] = player;
players[socket.id].id = socket.id;
console.log("Player " + player.userName + " with id: " + socket.id + " has joined.");
for (var key in players) {
console.log("Players: " + key + " : " + players[key].userName);
}
if (Object.size(players) == 2) {
io.sockets.emit('ready', true);
// socket.io initialization
var server = http.createServer(app).listen(3000);
var io = require('socket.io').listen(server);
io.set('log level', 1); // reduce logging
var movies = [],
rounds = [],
ready = false;
// Scrape IMDb Top 250 chart and store the titles in our movie array
var getTop250 = function () {
require('node.io').scrape(function() {
this.getHtml('http://www.imdb.com/chart/top?ref_=nb_mv_3_chttp', function(err, $) {
//Handle any request / parsing errors
if (err) this.exit(err);