Skip to content

Instantly share code, notes, and snippets.

Peter McDonnell petermd

Block or report user

Report or block petermd

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@petermd
petermd / stats.mongo
Created Jul 13, 2017
Get database collections and size sorted in descending order
View stats.mongo
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) + ")"); }
View mock-kubectl.sh
#!/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" "$@"
View emoji.groovy
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 {
View keybase.md

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:

View luhn.cljs
(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 []
@petermd
petermd / desummit
Last active Aug 29, 2015
leet javascript
View desummit
$(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');
@petermd
petermd / gist:9806313
Created Mar 27, 2014
getting remote ip from ServerWebSocket
View gist:9806313
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
View pivotal_notify.py
#!/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
You can’t perform that action at this time.