Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
#
# When you are working on your macbook sitting in cafe and you have to go pee,
# you need some way to guard you machine.
#
# Start this script, remove any earphones, and go do the job.
# The assumption is the thief will close the lid of the laptop before taking it away.
# This script detects the closing of the lid and plays some loud audio that will
# likely distract the thief and/or grab attention of nearby people, making the
x <- 1:50
case_when(
x %% 35 == 0 ~ "fizz buzz",
x %% 5 == 0 ~ "fizz",
x %% 7 == 0 ~ "buzz",
TRUE ~ as.character(x)
)
class BookGen
URL = 'http://betterexplained.com/calculus/lesson-'
EBOOK = 'calculus_better_explained.epub'
def gen_book
gen_original
gen_edited
gen_epub
gen_kindle
end
curl ipinfo.io
# http://superuser.com/questions/556029/how-do-i-convert-a-video-to-gif-using-ffmpeg-with-reasonable-quality
# http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
m2g() {
movie=$1
filters="fps=15,scale=$2:-1:flags=lanczos"
palette="/tmp/palette.png"
dtop="/Users/blah/Desktop"
ffmpeg -v warning -i $movie -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -i $movie -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y "$dtop/$movie.gif"
'.source.gfm':
'Email item':
'prefix': 'email'
'body': '### $1. [$2][$3]\n_<strong>$4</strong>_\n\n$5\n\n[$3]:$6\n\n***\n$7'
# get multiple quantmod returns
require(quantmod)
require(PerformanceAnalytics)
symbols <- c("CNSAX", "FAHDX", "VUSTX", "VFISX", "PREMX")
getSymbols(symbols, from='1900-01-01')
prices <- list()
for(symbol in symbols) {
prices[[symbol]] <- Ad(get(symbol))
}
# http://allthingsr.blogspot.com.au/2012/10/pull-yahoo-finance-key-statistics.html
metrics <- yahooQF(c('Price/Sales', 'P/E Ratio', 'Market Capitalization'))
tickers <- c('FB', 'TWTR')
q <- getQuote(paste(tickers, sep='', collapse=';'),what=metrics)
# http://www.smashingmagazine.com/2015/06/25/efficient-image-resizing-with-imagemagick/
resizeimage() {
# smartresize inputfile.png 300 outputdir/
# smartresize inputfile image_size outputdir
mogrify -path $3 -filter Triangle -define filter:support=2 -thumbnail $2 -unsharp 0.25x0.08+8.3+0.045 -dither None -posterize 136 -quality 82 -define jpeg:fancy-upsampling=off -define png:compression-filter=5 -define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude-chunk=all -interlace none -colorspace sRGB $1
}
require 'rest_client'
require 'json'
require 'csv'
require 'byebug'
# Use:
# urls = %w( array of urls )
# crawler = Crawler.new(urls)
# crawler.get_and_write_data
# change the directory or filename of the output file