Skip to content

Instantly share code, notes, and snippets.

@pch
pch / mac-vagrant-unison.md
Last active February 18, 2019 08:57
How to install Unison on Mac OS El Capitan & Vagrant

How to install Unison on Mac OS El Capitan & Vagrant - for Docker Sync

You can install Unison on the Mac via homebrew (brew install unison), but it's very likely that it won't work properly, resulting in errors like:

Unison failed: Uncaught exception Failure("input_value: bad bigarray kind")
Fatal error: Lost connection with the server
@pch
pch / gist:1322006
Created October 28, 2011 10:01
Spotify

How to use Spotify in any country

If you can put up with ads, you can easily trick Spotify and sign up for an account, even if you're not in one of the supported countries. You'll need:

  • A Facebook account
  • SSH access to a server based in one of the supported countries (US, UK, whatevs).

First, set up an SSH tunnel, as described here: http://paulstamatiou.com/how-to-surf-securely-with-ssh-tunnel

Keybase proof

I hereby claim:

  • I am pch on github.
  • I am pchm (https://keybase.io/pchm) on keybase.
  • I have a public key ASDohLNPHrR-IY6_I7lzw1SiENKSNNIKkmT9-BQIpRQoxQo

To claim this, I am signing this object:

@pch
pch / trimws.sh
Last active May 17, 2016 09:31
Nukes all trailing whitespace in the current project (rails specific).
find . -not \( -name .git -prune -o -name images -prune -o -name GeoLiteCity.dat -prune \) -type f -print0 | xargs -0 perl -pi -e 's/ +$//'
@pch
pch / watermark.rb
Created January 18, 2011 13:43
Paperclip Watermark processor
class User
has_attached_file :photo,
:processors => [:watermark],
:styles => {
:medium => {
:geometry => "300x300>",
:watermark_path => "#{Rails.root}/public/images/watermark.png"
},
:thumb => "100x100>",
}
require 'net/http'
out = `arp-scan -lq`
macs =
out.split("\n").map do |line|
if line =~ /([0-9A-F][0-9A-F :]{16})/i
puts $1
$1.split(' ').join(':').upcase
end
end.compact.join(',')
# 1
Foo.bar(
:one => 1,
:two => 2
)
# 2
Foo.bar(
:one => 1,
:two => 2)
module Devise
module Controllers
module ScopedViews
protected
# Monkey path for generating proper templates path when dealing with
# namespaced resources and custom views.
def render_with_scope(action, options={})
controller_name = options.delete(:controller) || self.controller_name
if self.class.scoped_views?
class String
def to_slug
s = self.gsub(/&/, 'and') # replace ampersand chars with 'and' before stripping HTML
s.gsub!(/<.*?>/, '') # strip HTML
s.gsub!(/&/, 'and') # replace ampersand chars with 'and'
s = Iconv.iconv('ascii//ignore//translit', 'utf-8', s).to_s # Borrowed partially from Technoweenie's PermalinkFu
s.gsub!(/\W+/, ' ') # all non-word chars to spaces
s.strip!
s.downcase!
s.gsub!(/[\W^-_]+/, '-') # replace non-word chars with dashes
#!/bin/bash
BACKUP_DIR='/home/rsync/mysql_backup'
MHOST='localhost'
MUSER='root'
MPASS='yourpass'
NOW=$(date +"%Y-%m-%d_%H")