Skip to content

Instantly share code, notes, and snippets.

Josh Graham delitescere

Block or report user

Report or block delitescere

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
@delitescere
delitescere / bootstrap.md
Last active May 8, 2019
Portola (OpenJDK using musl) on Alpine
View bootstrap.md

Get the JDK source (per the OpenJDK instructions):

hg clone http://hg.openjdk.java.net/portola/portola
cd portola
bash ./get_source.sh

You need an existing Alpine with an already-built JDK. I have a Docker image of Alpine with glibc-based Zulu JDK:

@delitescere
delitescere / cd-lessfuss.sh
Last active Nov 12, 2018
cd .. with less fuss
View cd-lessfuss.sh
# cd .. with multiple jumps or jump up to name
..() {
if [ "-" = "$1" ]; then cd -; return; fi; # return to previous directory
if [ "/" = "$1" ]; then cd /; pwd; return; fi; # jump to root
if [ -z "$1" ]; then cd ../; pwd; return; fi; # jump up one
declare -i count=$1; # get a jump count
if [ $count -eq 0 ]; then # wasn't a number, look for name
local go=$(while [ "/" != "$PWD" ] && [ "$(basename $PWD)" != "$1" ]; do cd ..; done; pwd);
# jump up to named directory, or don't move if name wasn't found
if [ "/" != "$go" ]; then cd $go; else return; fi;
@delitescere
delitescere / pwned-passwd.sh
Last active Apr 10, 2018
Check a pwned password from the macOS / bash command line
View pwned-passwd.sh
pwned-passwd ()
{
history -d $((HISTCMD - 1));
sha=$(printf $1 | sha1sum | cut -d' ' -f1 | tr [:lower:] [:upper:]);
prefix=${sha:0:5};
suffix=${sha:5};
count=$(curl -Ss https://api.pwnedpasswords.com/range/$prefix | grep $suffix | cut -d':' -f2);
[ -n "$count" ] && echo $count >&2 && return 1;
return 0;
@delitescere
delitescere / index
Last active Aug 6, 2017
JSON Home file 3
View index
{"api":{"title":"Scan Data","links":{"describedBy":"https://mport.com/api-docs/scan-data","author":"mailto:api@mport.com?subject=scan-data+json-home"}},"resources":{"tag:https://mport.com/api-docs/scan-data/resource/scans":{"hints":{"formats":{"application/edn":{},"application/json":{}},"allow":["GET"],"authSchemes":[{"scheme":"Bearer"}]},"href":"/scan/"},"tag:https://mport.com/api-docs/scan-data/resource/scan":{"hints":{"formats":{"application/edn":{},"application/json":{}},"acceptRanges":["items"],"acceptPut":["application/json","application/edn"],"acceptPost":["application/json","application/edn"],"allow":["GET","POST","PUT","DELETE"],"authSchemes":[{"scheme":"Bearer"}]},"hrefVars":{"scan-id":"https://mport.com/api-docs/scan-data/param/scan-id"},"hrefTemplate":"/scan/{scan-id}"}}}
@delitescere
delitescere / project.clj
Last active Jun 23, 2017
Mostly Java-based lein project with JUnit and Log4J2 (main.clj is still entry point)
View project.clj
(defproject com.example/foo "0.1.0"
:description "Does fooness"
:url "http://example.com/"
:license {:name "Copyright ©2014 Josh Graham"}
:aliases {"dist" ["do" ["clean"] ["test"] ["uberjar"]] ;$ lein dist # create distribution JAR
"debug" ["with-profile" "dev,debug" "run"]} ;$ lein debug # run for a 'remote' debugger
:aot :all
:auto-clean false ;"dist" alias does the full cycle
:clean-targets ^{:protect false} [:target-path :junit-results-dir]
:dependencies [
@delitescere
delitescere / index.html
Created May 23, 2017
Handlebars client-side templates
View index.html
<!DOCTYPE html>
<html>
<head>
<title>Greeting</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.10/handlebars.min.js"></script>
</head>
<body>
<h1>Greetings!</h1>
View gist:2594472
lazy val defaultBrowserVersion = Play.configuration.getString("snapshot.browserVersion")
.map(extractVersion _)
.getOrElse(BrowserVersion.FIREFOX_3_6) // Firefox 3.6 makes a good default because it works on all OSes
// Do you really need to throw an exception? Why not log it as an error, and return None so you end up with the default above?
def extractVersion(browserString: String): Option[BrowserVersion] = {
allCatch opt {
Some(classOf[BrowserVersion].getField(browserString).get(null).asInstanceOf[BrowserVersion])
}
View gist:2594342
aMap.get("a key that might not exist")
.map(expressionUsingTheValue(_))
.getOrElse(anotherExpression)
@delitescere
delitescere / gist:2155822
Created Mar 22, 2012
How to get the HTTP Request to the authenticate method?
View gist:2155822
tuple(...
).verifying("Invalid username or password", _ match {
case (Some(u), Some(p), _) => authenticate(u, p)
...
})
You can’t perform that action at this time.