Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am jgornick on github.
  • I am jgornick (https://keybase.io/jgornick) on keybase.
  • I have a public key whose fingerprint is 8215 CFA5 BEE5 C06E 9E25 9B34 A4E4 F2DE F764 D124

To claim this, I am signing this object:

@jgornick
jgornick / gist:eace131a44a2b594d51f1b3d9f94e6ca
Last active June 15, 2016 00:15
MongoDB: Remove array item _from_ nested embedded array.
db.foo.remove({});
db.foo.insert({ _id: 1, channels: [ { number: 1, history: [ { value: 1, date: new Date(+new Date) }, { value: 2, date: new Date(+new Date - (1000*60*3)) }, { value: 3, date: new Date(+new Date - (1000*60*10)) }] } ] });
db.foo.insert({ _id: 2, channels: [ { number: 1, history: [ { value: 1, date: new Date(+new Date) }, { value: 2, date: new Date(+new Date - (1000*60*10)) }, { value: 3, date: new Date(+new Date - (1000*60*15)) }] } ] });
db.foo.find();
db.foo.update({ 'channels.history': { $elemMatch: { date: { $lte: new Date(+new Date - (1000*60*5)) } } } }, { $pull: { 'channels.$.history': { date: { $lte: new Date(+new Date - (1000*60*5)) } } } }, { multi: true });
db.foo.find();
@jgornick
jgornick / watch-interactive-process.sh
Last active May 25, 2016 19:27
Bash: Watch Interactive Process
poke-interactive-process () {
while :; do
printf '\n'
sleep 1
done
}
watch-interactive-process () {
local args=( "$@" )
@jgornick
jgornick / docker-cleanup.sh
Created May 20, 2016 19:07
Docker: Cleanup (Remove all exited containers and dangling images)
#!/bin/bash
docker rm $(docker ps -q -f status=exited)
docker rmi $(docker images -q -f dangling=true)
@jgornick
jgornick / timeout.sh
Last active April 26, 2016 17:14
Bash: Timeout Example
now() {
local format="${1:-"%s"}"
echo -n "$(date -u +"$format")"
}
# Extract the last element of a list.
last() {
echo -n "${@:(-1)}"
}
@jgornick
jgornick / iptables.rules
Last active April 8, 2016 15:27
iptables: Forward via specific port between interfaces.
*filter
# Allow all outgoing, but drop incoming and forwarding packets by default
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
# Don't attempt to firewall internal traffic on the loopback device.
-A INPUT -i lo -j ACCEPT
@jgornick
jgornick / get-cell-signal.sh
Last active December 26, 2019 19:09
Bash: Get Cell Signal Strength
#!/bin/bash
. /usr/bin/pdivt-funcs
pipe="$(mktemp -u)"
log info "Logging cell signal level..."
log info "Creating fifo at $pipe..."
mkfifo $pipe
@jgornick
jgornick / iptables.rules
Last active March 31, 2016 19:17
iptables: Redirect port
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
# Redirect FTP port 11121 from 0/0 to 21.
-A PREROUTING -p tcp --dport 11121 -j REDIRECT --to-ports 21
@jgornick
jgornick / music.md
Last active March 29, 2016 16:41
Missing Music Service Features

Missing Music Service Features

The following is an evolving list of features that are missing from online music services.

Disclaimer: I am an old Rdio user and enjoyed how their experience was focused on discovering new music. Most of these features relate to discovering new music. However, there are some that improve the overall experience. I created this list after using Apple Music and most recently Google Play Music.

  • New releases includes all albums released this week, only. This is a wonderful way to discover new artists that may be releasing their new LP, EP or single.
  • New releases can be filtered to show last week releases and even the week before that.
  • New releases is automatically sorted by play counts so popularity is driven by the community. This promotes non-mainstream artists to be discovered.
  • New releases can also be sorted by music service recommendations. A recommendation can either be music service driven (e.g. "Google Play Music Featured Artist") or by the similar artist
@jgornick
jgornick / helpers.sh
Last active March 22, 2023 10:10
Bash: Helper Functions
#!/bin/bash
# Returns a UTC timestamp of the current date/time.
# Can provide an optional format that matches date(1) format
now() {
local format="${1:-"%s"}"
echo -n "$(date -u +"$format")"
}
# Extract the first element of a list.