Skip to content

Instantly share code, notes, and snippets.

@samholst
samholst / aws_signed_request_v4.rb
Created April 28, 2018 02:46 — forked from blelump/aws_signed_request_v4.rb
Sample Ruby code to create AWS signed request version 4 (with request headers)
#Signing AWS Requests By Using Signature Version 4
#http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html
require 'uri'
require 'openssl'
require 'net/http'
require 'cgi'
method = 'GET'
service = 'iam'
@samholst
samholst / README.md
Created May 3, 2018 02:47 — forked from terenceponce/README.md
Setting up rbenv, Ruby 2.1, Rails 4.1.0.beta1, nginx, Passenger, PostgreSQL 9.1 on Ubuntu 12.04 LTS for Windows Azure

Setting up Ruby, Rails, Nginx, Passenger, PostgreSQL 9 on Ubuntu 12.04 LTS for Windows Azure

Last updated: 12/31/2013

Fix the locale issue

  • Edit /etc/default/locale as sudo.
  • Append LC_ALL="en_US.UTF-8" at the end of the file, save and quit.
  • sudo locale-gen en_US en_US.UTF-8
  • sudo dpkg-reconfigure locales

Install the necessary packages to install rbenv and build Ruby

@samholst
samholst / fail2ban_notifier.rb
Created May 8, 2018 23:00 — forked from etdsoft/fail2ban_notifier.rb
Simple Fail2banNotifier for exception_notification (will submit a pull request and update gist when accepted). See: http://securityroots.com/blog/2014/01/protecting-app-rails-fail2ban/
class Fail2banNotifier
def initialize(options)
@default_options = options
@default_options[:logfile] ||= Rails.root.join('log', 'fail2ban.log')
# Roll over every 30M, keep 10 files
@logger ||= Logger.new(@default_options[:logfile], 10, 30*1024*1024)
end
def call(exception, options={})
= form_for(@tank_configuration) do |f|
- if @tank_configuration.errors.any?
#error_explanation
h2
= pluralize(@tank_configuration.errors.count, "error")
| prohibited this tank_configuration from being saved:
ul
- @tank_configuration.errors.full_messages.each do |msg|
li
= msg
@samholst
samholst / The Supermarket Queue.rb
Created June 4, 2018 19:31 — forked from wowdyaln/The Supermarket Queue.rb
[codewar] The Supermarket Queue
def queue_time(queue, cashier)
# 每個位置一起減去當中最小的值
def subtract_the_min(arr)
arr.map do |ele|
ele - arr.min
end
end
# 如果 at_a_certain_moment 裡面有0 -> 找到這個位置,塞入下一個顧客 ->直到每個位置都不是0
@samholst
samholst / ssl_puma.sh
Created July 5, 2018 06:30 — forked from tadast/ssl_puma.sh
localhost SSL with puma
# 1) Create your private key (any password will do, we remove it below)
$ cd ~/.ssh
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
@samholst
samholst / backup-github-repos.pl
Created January 21, 2019 23:15 — forked from njh/backup-github-repos.pl
Script to download/clone all of your Github repos
#!/usr/bin/perl
#
# Script to download/clone all of your Github repos
#
# Copyright Nicholas Humfrey, 22nd August 2017
#
# License: http://unlicense.org
#
use JSON;
#!/usr/bin/ruby
# Create display override file to force Mac OS X to use RGB mode for Display
# see http://embdev.net/topic/284710
require 'base64'
data=`ioreg -l -d0 -w 0 -r -c AppleDisplay`
edids=data.scan(/IODisplayEDID.*?<([a-z0-9]+)>/i).flatten
vendorids=data.scan(/DisplayVendorID.*?([0-9]+)/i).flatten
@samholst
samholst / mysql2-mojave.md
Created February 20, 2019 03:56 — forked from fernandoaleman/mysql2-mojave.md
Install mysql2 on MacOS Mojave

Problem

Installing mysql2 gem errors on MacOS Mojave.

Solution

Make sure openssl is installed on Mac via Homebrew.

brew install openssl
# config/initializers/activestorage.rb
Rails.application.config.to_prepare do
# Provides the class-level DSL for declaring that an Active Record model has attached blobs.
ActiveStorage::Attached::Macros.module_eval do
def has_one_attached(name, dependent: :purge_later, acl: :private)
class_eval <<-CODE, __FILE__, __LINE__ + 1
def #{name}
@active_storage_attached_#{name} ||= ActiveStorage::Attached::One.new("#{name}", self, dependent: #{dependent == :purge_later ? ":purge_later" : "false"}, acl: "#{acl}")
end