Skip to content

Instantly share code, notes, and snippets.

Proposal: JavaScript String.prototype.count()

Example

> s = 'abc/d/efg/h'
> s.count('/')
3
@mikez
mikez / close-other-apps
Last active April 15, 2022 20:59
Close all apps except the frontmost visible one. macOS only.
#!/bin/bash
# get frontmost app
frontmost_app=$(osascript -e '
tell application "System Events"
POSIX path of (file of application processes whose frontmost is true and visible is true)
end tell
')
escaped_frontmost_app=${frontmost_app//\//\\/}
@mikez
mikez / multisub.py
Created December 9, 2013 21:31
Proposed Stripe Python syntax for multiple subscriptions
# create a new subscription
customer.subscriptions.create(plan='basic')
# delete a subscription
customer.subscriptions.retrieve(subscription_id).delete()
# update a subscription
subscription = customer.subscriptions.retrieve(subscription_id)
subscription.trial_end = modified_trial_end
subscription.plan = subscription.plan.id # if possible, change API to make this superfluous.
print "hello world"