Skip to content

Instantly share code, notes, and snippets.

@barnabee
barnabee / NumberAwareStringComparator.java
Created February 3, 2012 00:15
Java string comparator that sorts numbers within the strings as complete numbers rather than character by character.
import java.util.Comparator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class NumberAwareStringComparator implements Comparator<String> {
private static final Pattern splitter = Pattern.compile("([-]?[\\d]+(?:\\.[\\d]+)?|[\\D]+)");
private static final Pattern matchNumber = Pattern.compile("[-]?\\d+(?:\\.[\\d]+)?");
@Override
@barnabee
barnabee / leap_gesture_test.js
Created September 16, 2013 16:57
Test simple Leap Motion gesture recognition with node.js
var _ = require('underscore')
var Leap = require('leapjs')
/*** Decompose X, Y, Z vector to simple direction */
var getDirection = function(vector) {
// Only do this if vector is defined and has length 3
if (vector && vector.length == 3) {
@barnabee
barnabee / curryable.js
Last active January 3, 2016 14:19
Example of a function that can wrap any function to make it support partial application. Relies on fun.length returning the number of expected arguments (e.g. all arguments included in function definition, not variable/implied from arguments object).
/**
** Example for creating curryable functions
**/
// Helper to splice together 2 arrays, like arr.concat() except elements in 'arr1' containig 'empty'
// are first "filled" with elements from arr2.
// e.g. splice(['a', undefined, 'b'], ['c', 'd', 'e']) --> ['a', 'c', 'b', 'd', 'e']
var splice = function (arr1, arr2, empty) {
var arr2_ = Array.prototype.slice.call(arr2, 0), // so this works with arguments objects
result = Array.prototype.slice.call(arr1, 0);
@barnabee
barnabee / Nitrous quick start
Last active August 29, 2015 13:56
How to set up Express, MongoDB and Mongoose on a Nitrous.IO NodeJS box.
To install MongoDB: "Autoparts" menu then "Manage Packages", search for MongoDB then
click "Install" then when done click "Start".
To install Express, in the console type:
npm install express -g<ENTER>
To create a new app. with folder structure ready to go, in the console type the following:
express ~/APPNAME --ejs<ENTER>
cd ~/APPNAME<ENTER>
npm install<ENTER>
bair:~ barnaby$ telnet google.com 80
Trying 173.194.116.137...
Connected to google.com.
Escape character is '^]'.
GET /
HTTP/1.0 302 Found
Location: http://www.google.co.uk/?gws_rd=cr&ei=f3ALU8aeIoeM4wTnl4HQDg
Cache-Control: private
Content-Type: text/html; charset=UTF-8
@barnabee
barnabee / keybase.md
Created April 22, 2014 13:42
Keybase proof

Keybase proof

I hereby claim:

  • I am barnabee on github.
  • I am barnabee (https://keybase.io/barnabee) on keybase.
  • I have a public key whose fingerprint is 75B6 19EC 7EDA 6EE1 C4B1 81A3 1D09 A19C 9CD3 A099

To claim this, I am signing this object:

#### Python should have indent-based alternatives to wrapping in all types of bracket
#
# Benefits:
# - indentation means no brackets to match n levels deep
# - new lines can replace commas, easy to reorder
# - feels nice and Pythony, works with the rest of the syntax
# - looks much cleaner and more readable without closing brackets and commas
#
# Instead of this
@barnabee
barnabee / vega_rewards_widget.py
Last active December 20, 2021 17:22
Simple iOS widget with Pyto to display Vega reward pool status
from datetime import datetime, timedelta
import math
import widgets as wd
import datetime as dt
import requests
VEGA_TOKEN_ASSET_ID = 'd1984e3d365faa05bcafbe41f50f90e3663ee7c0da22bb1e24b164e9532691b2'
# PAYOUT_DELAY_NETPARAM = 'reward.staking.delegation.payoutDelay'
PAYOUT_PER_EPOCH_NETPARAM = 'reward.staking.delegation.maxPayoutPerEpoch'
@barnabee
barnabee / coinbase_auth.py
Last active April 6, 2022 13:08
Coinbase REST API auth (Python)
import time
import hmac
import hashlib
import requests
import base64
class CoinbaseAuth(requests.auth.AuthBase):
def __init__(self, api_key, secret_key, api_passphrase):
self.api_key = api_key
@barnabee
barnabee / bm_jellybeans.toml
Last active July 11, 2024 11:15
Helix editor config
inherits = "jellybeans"
"ui.background" = {}