Skip to content

Instantly share code, notes, and snippets.

View whardier's full-sized avatar
🧨
Code...

Shane R. Spencer whardier

🧨
Code...
View GitHub Profile
@whardier
whardier / gist:1239654
Created September 24, 2011 18:12
MongoDB Min/Max Example (With accompanying annoyingly large but useful index)
# The data
> db.minmax.find()
{ "_id" : ObjectId("4e7e1814f836a6cd3f414909"), "ichi" : 13046, "ni" : 28664, "san" : 16392 }
{ "_id" : ObjectId("4e7e1814f836a6cd3f41490a"), "ichi" : 21565, "ni" : 6487, "san" : 23549 }
{ "_id" : ObjectId("4e7e1814f836a6cd3f41490b"), "ichi" : 21904, "ni" : 29534, "san" : 15345 }
{ "_id" : ObjectId("4e7e1814f836a6cd3f41490c"), "ichi" : 22511, "ni" : 4158, "san" : 32184 }
{ "_id" : ObjectId("4e7e1814f836a6cd3f41490d"), "ichi" : 16347, "ni" : 22774, "san" : 3930 }
{ "_id" : ObjectId("4e7e1814f836a6cd3f41490e"), "ichi" : 26574, "ni" : 2486, "san" : 17466 }
{ "_id" : ObjectId("4e7e1814f836a6cd3f41490f"), "ichi" : 29113, "ni" : 16052, "san" : 17271 }
{ "_id" : ObjectId("4e7e1814f836a6cd3f414910"), "ichi" : 25451, "ni" : 3725, "san" : 24723 }
>>> num = "15558675309"
>>> [num[0:x] for x in range(1, len(num))]
['1', '15', '155', '1555', '15558', '155586', '1555867', '15558675', '155586753', '1555867530']
>>> [num[x:] for x in range(1, len(num))]
['5558675309', '558675309', '58675309', '8675309', '675309', '75309', '5309', '309', '09', '9']
@whardier
whardier / gist:1990434
Created March 7, 2012 02:03
Timezone Dict Merge
#!/usr/bin/python
timezones_account_one= {
'United States of America': {
'Alaska': {
'America/Adak': 'Adak, Alaska, USA',
'America/Anchorage': 'Anchorage, Alaska, USA',
},
'Idaho': {
'America/Los_Angeles': 'Coeur\'d Alene, Idaho, USA',
>>> import hashlib
>>> import humanhash
>>> mysupersecrethash = hashlib.md5('mysupersecretpassword').hexdigest()
>>> mysupersecrethash
'117a520adbd19eff51100215aa7a7fbf'
>>> humanhash.humanize(mysupersecrethash)
'diet-johnny-green-bacon'
@whardier
whardier / gist:2007883
Created March 9, 2012 18:24
Multicast message pub/sub test
import zmq
import uuid
import random
context = zmq.Context()
recv = context.socket(zmq.SUB)
recv.setsockopt(zmq.SUBSCRIBE, '')
recv.connect('epgm://eth0;224.0.0.1:5555')
remote refid st t when poll reach delay offset jitter
==============================================================================
+66.96.96.29 18.26.4.105 2 u 115 128 377 123.790 3.285 12.293
+208.87.104.40 206.246.122.250 2 u 48 128 377 113.327 3.790 5.833
-2600:3c00::e:d0 209.51.161.238 2 u 126 128 377 199.939 -17.237 27.844
*173.244.211.10 204.42.158.152 2 u 54 128 377 41.247 3.867 21.763
x127.127.28.0 .GPS. 0 l 9 16 377 0.000 -10614. 37.478
127.127.28.1 .GPS1. 0 l - 64 0 0.000 0.000 0.000
@whardier
whardier / gist:3882493
Created October 13, 2012 00:14
Simple ZMQ/Standard Socket Server Poller Mixing.
import select
import time
import zmq
import socket
context = zmq.Context()
dealer = context.socket(zmq.DEALER)
dealer.connect('tcp://localhost:5570')
@whardier
whardier / gist:3882495
Created October 13, 2012 00:15
Simple ZMQ/Standard Socket Server Poller Mixing.
import time
import zmq
import socket
context = zmq.Context()
dealer = context.socket(zmq.DEALER)
dealer.connect('tcp://localhost:5570')
@whardier
whardier / gist:3903832
Created October 17, 2012 05:24
Some habits die hard.
sspencer@bigboote:~$ cat /usr/bin/nano
#!/bin/sh
echo "Use VIM newb."
sspencer@bigboote:~$ :)
entry_points={
'console_scripts': [
'whachuptu = whachuptu.__main__:run',
],
}
"""
(whachuptu)sspencer@bigboote:~/Projects/whachuptu$ python -m whachuptu asdf
['/home/sspencer/Projects/whachuptu/whachuptu/__main__.py', 'asdf']
yay!