Category: Code Snippet
My custom bash prompt
I wanted more information in my bash prompt, such as date/time and the directory I was in. Here’s what it looks like: And this is what I added in my ~/.bash_profile: PS1='${debian_chroot:+($debian_chroot)}\d \T > \[$(tput sgr0)\]\[\033[01;32m\]\u@\h\[\033[00m\] : \[\033[01;34m\]\w\[\033[00m\]\n\$ ' Run source ~/.bash_profile and enjoy. 🙂 BTW, there’s also a website that you can use to…
Unpretty print a JSON file
I needed a one-liner JSON payload, but only had the pretty-printed version. And, removing the whitespaces manually was NOT an option. It was super easy on a Mac; just do the following: In a terminal, install “jq” with brew like so brew install jq With your pretty-printed JSON in a file: cat prettyprinted.json | jq…
Mongo DB: Iterate through a MongoCollection
This is specifically for Mongo 3.x, where MongoCollection is preferred over DBCollection. Adding for personal archiving. MongoCollection<Document> mongoCollection = getMongoCollection(databaseName, collectionName); FindIterable<Document> documents = mongoCollection.find(eq(COLUMN, "lastName")) .sort(ascending("lastname")); for (Document document : documents) { … }
Importing Apple Notes into Evernote
Just copy and paste the following into the Script Editor and viola! tell application "Notes" set theMessages to every note repeat with thisMessage in theMessages set myTitle to the name of thisMessage set myText to the body of thisMessage set myCreateDate to the creation date of thisMessage set myModDate to the modification date of thisMessage…
How to copy file permissions from one to another
chmod `stat -f %A srcFile` dstFile via Non Geek Recipes How to copy file permissions – nongeekrecipes.org.
Install wget on OS X Mountain Lion
From the terminal, do the following: curl -O http://ftp.gnu.org/gnu/wget/wget-1.13.tar.gz tar -xzvf wget-1.13.tar.gz cd wget-1.13 ./configure –with-ssl=openssl make sudo make install