Skip to content

Instantly share code, notes, and snippets.

View cmer's full-sized avatar

Carl Mercier cmer

  • Toronto, ON, Canada
View GitHub Profile
@cmer
cmer / custom.sh
Last active July 6, 2020 07:57
Script to update Wireguard routes in DD-WRT
#!/bin/bash
while :
do
WGPROC=$(wg)
WGIF=$(ip route show gateway | grep -io oet1)
WGSERVER=$(/usr/sbin/nvram get oet1_rem0)
WANGWY=$(/usr/sbin/nvram get wan_gateway)
WANIF=$(/usr/sbin/nvram get wan_iface)
@cmer
cmer / rmssh
Last active August 12, 2019 01:58
Script to remove last attempted SSH host from ~/.ssh/known_hosts
#!/usr/bin/env ruby
host = ARGV[0].to_s
if host == ""
history_output = `cat ~/.bash_history | grep "^ssh\s" | tail -1`
host = history_output.sub(/^ssh\s/i, '').split("@").last.split(" ").first
end
puts `ssh-keygen -R #{host}`
@cmer
cmer / no_automount
Last active December 23, 2018 05:45 — forked from voltechs/no_automount
Add volume (UUID) to fstab to prevent automount (macOS)
#!/usr/bin/env ruby
# Usage: no_automount /Volumes/My\ Disk
if ARGV[0].nil?
puts "Usage: no_automount /Volumes/My\ Disk"
exit 1
end
diskinfo = `diskutil info '#{ARGV[0]}'`.gsub("\n\n", "\n").split("\n").collect do |b|
@cmer
cmer / config.ru
Last active December 31, 2023 15:34
Gem In a Box basic authentication & authorization rackup file
#
# This is a simple rackup file for geminabox. It allows simple role-based authorization.
#
# roles:
# - developer
# - upload
# - delete
# - admin (can do anything)
#
# For example, a developer who can access the service and upload new gems would have the following roles: `%w(developer upload)
@cmer
cmer / ping_check.sh
Last active March 9, 2023 17:12
Auto reboot pfSense if Internet is down
#!/bin/sh
#
# /usr/local/bin/ping_check.sh
#
# First sleep for 3 mins so that we don't run this code if box has only just booted and PPPoE not up yet.
/bin/sleep 180
test_http() {
url=${1:-http://captive.apple.com}
@cmer
cmer / haproxy.cfg
Last active April 15, 2024 09:54
Simple, no bullshit TCP port forwarding using HAProxy
listen l1
bind 0.0.0.0:443
mode tcp
timeout connect 4000
timeout client 180000
timeout server 180000
server srv1 host.example.com:9443

Keybase proof

I hereby claim:

  • I am cmer on github.
  • I am cmer (https://keybase.io/cmer) on keybase.
  • I have a public key whose fingerprint is D086 FC72 06E0 89F8 7FAE C495 E5F6 43EA 38F0 16D0

To claim this, I am signing this object:

@cmer
cmer / gist:6063133
Created July 23, 2013 15:10
Hetzner EX40 UnixBench
# # # # # # # ##### ###### # # #### # #
# # ## # # # # # # # ## # # # # #
# # # # # # ## ##### ##### # # # # ######
# # # # # # ## # # # # # # # # #
# # # ## # # # # # # # ## # # # #
#### # # # # # ##### ###### # # #### # #
Version 5.1.3 Based on the Byte Magazine Unix Benchmark
Multi-CPU version Version 5 revisions by Ian Smith,
# routes.rb
put '/payment_details' => 'payment_details#update'
# controller
class PaymentDetails < Controller
def update
stripe = Stripe.new
stripe.email = params[:stripe][:email]
stripe.address = params[:stripe][:address]
@cmer
cmer / gist:3821654
Created October 2, 2012 17:50
Ok, Ruby. What's the real here?
[1] pry(#<NotificationCreationService>)> record
=> #<Item id: 58, kind: 1, user_id: 79, community_id: 43, category_id: nil, root_category_id: nil, title: "Autem optio molestias unde laudantium fugit officii...", description: "Aut at quod officiis repellendus. Expedita pariatur...", price: nil, original_price: nil, lowest_price: nil, price_drop_count: 0, for_sale: nil, status: nil, bump_position: 1029, published_at: "2012-09-22 17:48:13", last_bumped_at: "2012-09-23 17:48:13", deleted_at: nil, created_at: "2012-09-22 17:48:13", updated_at: "2012-10-02 17:48:13">
[2] pry(#<NotificationCreationService>)> record.is_a?(Item)
=> false
[3] pry(#<NotificationCreationService>)> record.class.name
=> "Item"
[4] pry(#<NotificationCreationService>)> record.class
=> Item(id: integer, kind: integer, user_id: integer, community_id: integer, category_id: integer, root_category_id: integer, title: string, description: string, price: decimal, original_price: decimal, lowest_price: decimal, price_drop_count: integer, for_sale: b