Skip to content

Instantly share code, notes, and snippets.

@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>",
}
@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/ +$//'

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 / 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

@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 / encrypted-tokens.md
Created June 1, 2020 10:17
Encrypted Tokens Between Rails and Node

Encrypted Tokens Between Rails and Node

If you need to pass data safely between Rails and Node, you can use the built-in Rails encryption.

The script below wraps ActiveSupport::MessageEncryptor, allowing to create expiring JSON tokens that can be decoded in Node using a shared secret.

secret = "866b914a169d3969849966febafe8057bec6b82ea477e64682a11a2e61096797"
payload = { user_id: 1, name: "John Doe", role: "admin" }
EncryptedToken.encode(payload: payload, expires_at: 10.minutes.from_now, secret: secret)
@pch
pch / git-sync
Last active August 30, 2021 08:57
Git sync - light version
#!/bin/sh
git_branch() {
echo $(git symbolic-ref HEAD 2>/dev/null | awk -F/ {'print $NF'})
}
git_dirty() {
st=$(git status 2>/dev/null | tail -n 1)
if [[ $st == "" ]]
then
#!/usr/bin/env ruby
#
# Recreate Lightroom catalog by replacing corrupt files with recovered copies
#
# Keeps the directory structure and creates the new catalog in a new path,
# which means you'll need at least 3x the size of your photos of free space.
#
# Dependencies:
# - ruby
# - exiftool
#!/bin/bash
#
# Example pre-commit hook: triggers rubocop & eslint on staged files.
#
# To use it, create a symlink in your .git/hooks directory:
#
# $ ln -s $(pwd)/bin/pre-commit .git/hooks
set -e
# Ruby
function initComponent(root, goDeep = true) {
const component = root.dataset.component;
const targets = {};
const state = {};
root.querySelectorAll(`[data-${component}-target]`).forEach((attr) => {
targets[attr.getAttribute(`data-${component}-target`)] = attr;
});
Array.from(root.attributes).forEach((attr) => {