Skip to content

Instantly share code, notes, and snippets.

@nagachika
nagachika / .gitignore
Created May 29, 2015 02:57
picasa with OAuth 2.0
/.bundle
/vendor/bundle
/.envrc
@anton-rudeshko
anton-rudeshko / convert.sh
Last active October 17, 2020 01:01
Convert GoPro photos to timelapse video using ffmpeg CLI.
#!/usr/bin/env bash
# -r 60: 60 FPS
# -y: rewrite output file
# -start_number 11555: first frame number
# -i 'G%07d.JPG': file format
# -vf "crop=h=2250": video filter to crop input frame height from 3000 to 2250 (which will be eventually downscaled to 720)
# -c:v libx264: video codec x264
# -crf 20: x264 encoding quality (less = better)
# -s 1280x720: output size
@jareware
jareware / s3-curl-backups.md
Last active August 29, 2021 00:56
Simple, semi-anonymous backups with S3 and curl

⇐ back to the gist-blog at jrw.fi

Simple, semi-anonymous backups with S3 and curl

Backing stuff up is a bit of a hassle, to set up and to maintain. While full-blown backup suites such as duplicity or CrashPlan will do all kinds of clever things for you (and I'd recommend either for more complex setups), sometimes you just want to put that daily database dump somewhere off-site and be done with it. This is what I've done, with an Amazon S3 bucket and curl. Hold onto your hats, there's some Bucket Policy acrobatics ahead.

There's also a tl;dr at the very end if you just want the delicious copy-pasta.

Bucket setup

require 'rubygems'
require 'httparty'
require 'fileutils'
require 'json'
USERNAME = ARGV[0] || "patio11"
MAX_TO_FETCH = ARGV[1]
puts "Username: #{USERNAME} max to fetch: #{MAX_TO_FETCH || "all"}"
var randomNumbers = [42, 12, 88, 62, 63, 56, 1, 77, 88, 97, 97, 20, 45, 91, 62, 2, 15, 31, 59, 5]
func partition(v: Int[], left: Int, right: Int) -> Int {
var i = left
for j in (left + 1)..(right + 1) {
if v[j] < v[left] {
i += 1
(v[i], v[j]) = (v[j], v[i])
}
}

Write a program in Ruby that parses a dictionary file for unique sequences of letters.

Requirements:

  • The program should generate two output files, "sequences" and "words".
  • The sequences file should contain every unique sequence of four letters that are unique and appear in exactly one word of the dictionary file.
  • Differences in casing should not reflect a unique sequence.
  • Numbers and special characters should not create a unique sequence.
  • The words file should contain the corresponding words that contain the sequence, in the same order, again one per line.
@Nakilon
Nakilon / 2048.rb
Last active July 26, 2023 22:15
2048 golfed to 379 chars in Ruby by Nakilon for http://www.reddit.com/r/tinycode/comments/22wozn/
require"io/console"
_=[[_]*4]*4
t=->{_=_.transpose}
r=->{_.map! &:reverse}
f=->{_=_.map{|_|_=(_*?\s).gsub(/\b(\d+) +\1\b/){|_|_.to_i*2}.split;_[3]||=p;_}}
f[]
loop{(0while _[i=rand(4)][j=rand(4)];_[i][j]=[*[?2]*9,?4].sample)if$n!=_*?_
system"clear"
_.map{|_|puts"%5s"*4%_}
(c=STDIN.getch)[?q]|0
@chrisjlee
chrisjlee / querySelector.polyfill.js
Created February 12, 2014 17:39
IE document.querySelector() polyfill
if (!document.querySelectorAll) {
document.querySelectorAll = function (selectors) {
var style = document.createElement('style'), elements = [], element;
document.documentElement.firstChild.appendChild(style);
document._qsa = [];
style.styleSheet.cssText = selectors + '{x-qsa:expression(document._qsa && document._qsa.push(this))}';
window.scrollBy(0, 0);
style.parentNode.removeChild(style);

A future version of Ember will come with a new templating engine known as HTMLBars.

The original motivation for HTMLBars was to allow helpers and properties to have better contextual information about what they were bound to.

So for example, consider a template like this:

<a href="{{url}}">{{link}}</a>
@mitio
mitio / deploy.rb
Created August 23, 2013 15:38
Sidekiq + Capistrano + Ubuntu Upstart
# config/deploy.rb
namespace :upstart do
desc 'Generate and upload Upstard configs for daemons needed by the app'
task :update_configs, except: {no_release: true} do
upstart_config_files = File.expand_path('../upstart/*.conf.erb', __FILE__)
upstart_root = '/etc/init'
Dir[upstart_config_files].each do |upstart_config_file|
config = ERB.new(IO.read(upstart_config_file)).result(binding)