Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Daniel Norton dnorton

🏠
Working from home
View GitHub Profile
View python_tricks.md
  • validate JSON
cat data.json |python -m json.tool
@dnorton
dnorton / alias_myaccount.sh
Last active Mar 15, 2019
Alias command to show my AWS account id
View alias_myaccount.sh
alias myaccount="curl -s http://169.254.169.254/latest/dynamic/instance-identity/document|python -c 'from __future__ import print_function;import json,sys; print(json.load(sys.stdin)[\"accountId\"])'"
@dnorton
dnorton / time_pace.py
Created Feb 16, 2018
python methods to parse a list of mile times in the format "MM:SS"
View time_pace.py
"""Script to add up minutes:seconds and give average pace"""
def sum_times(*times):
'''arg list of MM:SS'''
return sum(map(lambda x: int(x.split(':')[0]) * 60 + int(x.split(':')[1]), times)), len(times)
def secs_to_mins(seconds, count):
@dnorton
dnorton / tuple.groovy
Last active Feb 13, 2017
example of tuples in groovy
View tuple.groovy
def a = new Tuple2(null, "string")
def b = new Tuple2("string", null)
def c = new Tuple2(null, "string")
assert a == c
assert a != b
m = [:]
m[b] = "value"
println m[b]
m[a] = "both"
View dedupe.py
def dedupe(original):
"""method to remove unnecessary ; and duplicate values"""
value_set = set(filter(bool, map(lambda it: it.strip(), original.split(';'))))
return '; '.join(list(value_set))
View keybase.md

Keybase proof

I hereby claim:

  • I am dnorton on github.
  • I am dnorton (https://keybase.io/dnorton) on keybase.
  • I have a public key whose fingerprint is 8958 331A 3F85 4AB4 9C5D D51B 319E C116 936D CEF5

To claim this, I am signing this object:

@dnorton
dnorton / sum_times.py
Last active Sep 14, 2016
python script to calculate average pace
View sum_times.py
"""Script to add up minutes:seconds and give average pace"""
def sum_times(*times):
'''arg list of MM:SS'''
return sum(map(lambda x: int(x.split(':')[0]) * 60 + int(x.split(':')[1]), times)), len(times)
def secs_to_mins(seconds, count):
@dnorton
dnorton / debug.gradle
Created Jun 13, 2016
A couple small tasks for debugging gradle
View debug.gradle
//debugging task to check the configuration
task list(dependsOn: configurations.compile) << {
println "classpath = ${configurations.compile.collect {File file -> file.name}}"
}
//debug -- show all dependency files
task showDependencyFiles(dependsOn:configurations.compile) {
configurations.compile.collect {
println it
}
View os_info.kt
fun main(args : Array<String>) {
println(System.getProperty("os.name"))
println(System.getProperty("os.arch"))
println(System.getProperty("os.version"))
}
View delete_readonly_dir.py
import shutil
import os
import stat
def remove_readonly(func, path, excinfo):
os.chmod(path, stat.S_IWRITE)
func(path)
shutil.rmtree("../../export", onerror=remove_readonly)