Skip to content

Instantly share code, notes, and snippets.

View nod's full-sized avatar
💻
i writes the codes, sometimes.

Jeremy Kelley nod

💻
i writes the codes, sometimes.
View GitHub Profile
>>> sample = {"a":2,"b":{"c":44}}
>>> sample.get("b",{}).get("c") # is gross
>>>
>>> class nestdict(dict):
... def __floordiv__(self, k):
... v = self.get(k)
... if isinstance(v, dict): return nestdict(v)
... return v
...
>>> z = nestdict(sample)
@nod
nod / gist:29a391f0eb4955d1ba3d34d12633fbbf
Last active November 7, 2017 17:23
For scala, using typesafe config, read default config and read runtime config if given via cmdline option
/*
Prior to this, I would build up `cfgMap` from my command line options.
If `'config` exists, that will load the run time config file and overlay it on top of the default config.
*/
// setup our default config
lazy val defaultConfig = ConfigFactory.parseResources("default.conf")
var conf = defaultConfig
// do we have a runtime config file?
val cfgFilePath = cfgMap.getOrElse('config, Nil)
Exception in thread "main" org.apache.spark.SparkException: Application application_1509398305238_0002 finished with failed status
at org.apache.spark.deploy.yarn.Client.run(Client.scala:1104)
at org.apache.spark.deploy.yarn.Client$.main(Client.scala:1150)
at org.apache.spark.deploy.yarn.Client.main(Client.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:755)
at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:180)
@nod
nod / uglytest.py
Created September 27, 2017 16:07
import random
import time
s = set()
for x in xrange(1000):
s.add(str(random.randint(1,1000000)))
d = {x:1 for x in s}
n = d.keys()[:400]
n.extend([ str(random.randint(1,1000000)) for i in xrange(1000) ])

Keybase proof

I hereby claim:

  • I am nod on github.
  • I am nod (https://keybase.io/nod) on keybase.
  • I have a public key whose fingerprint is 67FA B939 5A9C 1A30 5E3F DE2B 4FC8 016B 8E58 67CA

To claim this, I am signing this object:

@nod
nod / readme.md
Created February 19, 2016 16:21
Ionic in a directory... The easy way

local tooling for ionic

Instead of installing bower, gulp, ionic, cordova globally - I prefer to put them in the directory with the project. This way projects can have their own versions as needed.

dev

You'll create a file env.sh that lives at the root of your ionic project that you'll source when you start working to ensure everything is setup properly.

@nod
nod / textfind.py
Last active February 3, 2016 21:16
Use text search in mongo 3.2+ with pymongo
# For pymongo against mongodb 3.2...
# Given a collection of documents like
# {'textfield': 'cool stuff in a doc', 'other': 'fields...'}
#
# To perform the query, and get results sorted by the textual score:
db.my_collection.create_index([('textfield','text')])
cursor = db.my_collection.find(
{'textfield': 'some string query'},
@nod
nod / ios_icons
Last active August 29, 2015 14:13
Create iOS icons in the needed sizes from one image on OS X
#!/bin/sh
# usage: ios_icons some_file.png
# output: creates images in needed sizes for iOS icon files
# ex: some_file_SIZE.png
inf=$1
filename=$(basename "$inf")
ext="${filename##*.}"
@nod
nod / gist:0e12567203e94e3646c1
Created October 23, 2014 04:33
sample location stanzas for nginx to proxy back to couchbase syncgateway
location /syncgw {
proxy_pass http://127.0.0.1:4984/syncgw;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass_header Server;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass_header Accept;
@nod
nod / minimal_ansible_playbook.py
Last active July 17, 2024 10:54
Minimal code to run an Ansible Playbook from within python and get stats back on success or fail
from ansible import playbook, callbacks
# uncomment the following to enable silent running on the playbook call
# this monkey-patches the display method on the callbacks module
# callbacks.display = lambda *a,**ka: None
# the meat of the meal. run a playbook on a path with a hosts file and ssh key
def run_playbook(playbook_path, hosts_path, key_file):
stats = callbacks.AggregateStats()
playbook_cb = callbacks.PlaybookCallbacks(verbose=0)