Skip to content

Instantly share code, notes, and snippets.

View matiaskorhonen's full-sized avatar

Matias Korhonen matiaskorhonen

View GitHub Profile
# config/initializers/active_record_uuid_ids.rb
Rails.application.config.generators do |generator|
# Always use UUIDs for primary keys (when generating migrations)
generator.orm :active_record, primary_key_type: :uuid
end
@matiaskorhonen
matiaskorhonen / postgresapp_unix_socket.md
Last active June 15, 2021 21:37 — forked from iamvery/postgresapp_unix_socket.md
Setup Postgres.app to allow connections via unix sockets

These are instructions to setup Postgres.app to allow connections over unix sockets. These instructions were written for macOS Sierra (10.12) and Postgres.app 9.6.0

  1. Run Postgres.app once so that the configuration is initialized in ~/Library/Application Support/Postgres/var-9.6/
  2. Quit Postgres.app
  3. Open ~/Library/Application Support/Postgres/var-9.6/postgresql.conf in your favorite text editor
  4. Uncomment the line unix_socket_directories = '/tmp' and change it to unix_socket_directories = '/var/pgsql_socket,/tmp'
  5. Run sudo mkdir -p /var/pgsql_socket
  6. Run sudo chmod 770 /var/pgsql_socket
  7. Run sudo chown root:staff /var/pgsql_socket
// Underscore.js
// http://underscorejs.org
// (c) 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
// Underscore may be freely distributed under the MIT license.
//
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
@matiaskorhonen
matiaskorhonen / tumblr-to-middleman.rb
Created September 16, 2016 11:03
Tumblr blog post extraction code. Pretty much tailored for my needs when I migrated from Tumblr to Middleman, but this might still be of use to someone…
#!/usr/bin/env ruby
require "tumblr_client"
require "time"
require "yaml"
require "fileutils"
require "open-uri"
require "nokogiri"
require "loofah"
require "reverse_markdown"
@matiaskorhonen
matiaskorhonen / navbar_tab_builder.rb
Created August 11, 2016 07:16
Bootstrap v4 navbar tabs_on_rails tab builder
class NavbarTabBuilder < TabsOnRails::Tabs::Builder
def open_tabs(options = {})
options[:class] ||= "nav navbar-nav"
@context.tag("ul", options, open = true)
end
def close_tabs(options = {})
"</ul>".html_safe
end
@matiaskorhonen
matiaskorhonen / Chromium48.sh
Created April 20, 2016 11:04
Install Chromium 48 on Raspbian Jessie
wget https://launchpad.net/~canonical-chromium-builds/+archive/ubuntu/stage/+build/8883797/+files/chromium-browser_48.0.2564.82-0ubuntu0.15.04.1.1193_armhf.deb && \
wget https://launchpad.net/~canonical-chromium-builds/+archive/ubuntu/stage/+build/8883797/+files/chromium-codecs-ffmpeg-extra_48.0.2564.82-0ubuntu0.15.04.1.1193_armhf.deb && \
sudo dpkg -i chromium-codecs-ffmpeg-extra_48.0.2564.82-0ubuntu0.15.04.1.1193_armhf.deb chromium-browser_48.0.2564.82-0ubuntu0.15.04.1.1193_armhf.deb
@matiaskorhonen
matiaskorhonen / sign-pdf.rb
Last active March 21, 2025 02:34
Quick and dirty PDF signing in Ruby (using Origami)
#!/usr/bin/env ruby
require "openssl"
require "time"
begin
require "origami"
rescue LoadError
abort "origami not installed: gem install origami"
end
@matiaskorhonen
matiaskorhonen / letsencrypt-cf-updater.rb
Created February 23, 2016 08:44
A short Ruby script to push a Let's Encrypt certificate to AWS Cloudfront (via IAM). Also configures the distribution to use the newly uploaded certificate.
#!/usr/bin/env ruby
require "aws-sdk" # Ruby AWS SDK '~> 2'
cloudfront = Aws::CloudFront::Client.new
iam = Aws::IAM::Client.new
distribution_id = "..." # Add your Cloudfront distribution ID here
certificate_base_name = "..." # A prefix for the certificate name on CF
@matiaskorhonen
matiaskorhonen / check-certificate.rb
Last active April 19, 2021 21:53
Check an SSL/TLS certificate in Ruby (with SNI support)
# Modified from:
# http://findingscience.com/ruby/ssl/2013/01/13/reading-an-ssl-cert-in-ruby.html
require "socket"
require "openssl"
host = "www.piranhas.co"
tcp_client = TCPSocket.new("www.piranhas.co", 443)
ssl_client = OpenSSL::SSL::SSLSocket.new(tcp_client)
@matiaskorhonen
matiaskorhonen / toggle-tv-power off.sh
Created January 28, 2016 16:04
A quick script to control the power state of a TV attached to a Raspberry Pi over HDMI. Requires `cec-utils` to be installed.
#!/usr/bin/env bash
iso8601_date () {
date +%Y-%m-%dT%H:%M:%S%z
}
turn_on () {
echo 'on 0' | cec-client -s -d 1 RPI
}