Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View petermd's full-sized avatar

Peter McDonnell petermd

View GitHub Profile
@petermd
petermd / gist:9806313
Created March 27, 2014 12:20
getting remote ip from ServerWebSocket
public static
InetSocketAddress getRemoteAddress (final ServerWebSocket ws)
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException
{
InetSocketAddress addr = null;
final WebSocketImplBase requestWS = (WebSocketImplBase)ws;
Field f = WebSocketImplBase.class.getDeclaredField("conn"); //NoSuchFieldException
f.setAccessible(true);
ConnectionBase connectionBase = (ConnectionBase) f.get(requestWS); //IllegalAccessException
@petermd
petermd / desummit
Last active August 29, 2015 14:01
leet javascript
$(document).ready(function () {
//var end = new Date.getHours();
var currentMonth = (new Date).getMonth() + 1;
var currentDay = (new Date).getDate(); // create an instance of the date object
var datetoday = new Date(); // create new Date()
var timenow = datetoday.getTime(); // grabbing the time it is now
datetoday.setTime(timenow); // setting the time now to datetoday variable
var hournow = datetoday.getHours(); //the hour it is
var month = $('.CurrentMonth');
(defn sum-digits [num]
(+ (quot num 10) (mod num 10)))
(defn sum-doubleeven [idx num]
(sum-digits (if (even? idx) num (* num 2))))
(defn luhn? [num]
(zero? (mod (reduce + (map-indexed sum-doubleeven (reverse num))) 10)))
(defn test-luhn []

Keybase proof

I hereby claim:

  • I am petermd on github.
  • I am petermd (https://keybase.io/petermd) on keybase.
  • I have a public key whose fingerprint is 496A 7E97 F6D9 C7CA DCA9 E4CB E581 5637 A8F1 85CF

To claim this, I am signing this object:

import java.security.MessageDigest
def md5(String s) {
MessageDigest digest = MessageDigest.getInstance("MD5")
digest.update(s.bytes);
new BigInteger(1, digest.digest()).toString(16).padLeft(32, '0')
}
def check(p) {
try {
#!/usr/bin/env python
#
# post-commit hook for svn to notify pivotaltracker
#
# Posts commit to pivotal to enable auto-tracking of commits. Adds viewvc link if url provided. Place in SVN/hooks/post-commit as follows
#
# pivotal_notify.py -v "http://SVNSERVER/BIN/viewvc.cgi" "$REPOS" "$REV" "$PIVOTAL_API_TOKEN"
#
from xml.sax.saxutils import escape
#!/bin/bash
PASS_OPS=${KC_MOCK_PASS:-none}
FAIL_OPS=${KC_MOCK_FAIL:-none}
if [[ $FAIL_OPS == *"$1"* ]]; then
>&2 echo "$0: mock-fail" "$@"
exit 1
elif [[ $PASS_OPS == *"$1"* ]]; then
>&2 echo "$0: mock-pass" "$@"
@petermd
petermd / stats.mongo
Created July 13, 2017 12:29
Get database collections and size sorted in descending order
var collectionNames = db.getCollectionNames(), stats = [];
collectionNames.forEach(function (n) { stats.push(db[n].stats()); });
stats = stats.sort(function(a, b) { return b['size'] - a['size']; });
for (var c in stats) { print(stats[c]['ns'] + ": " + stats[c]['size'] + " (" + stats[c]['storageSize']/(1024*1024) + ")"); }