Skip to content

Instantly share code, notes, and snippets.

View adamrunner's full-sized avatar

Adam Runner adamrunner

View GitHub Profile
@adamrunner
adamrunner / update-openvpn-certs.sh
Last active April 9, 2024 00:37
Shell script to automate installation of new LetsEncrypt certs into OpenVPN Access Server when they have been renewed
#!/bin/bash
# this script is used to update the openvpn access server certificates after
# certbot renews the certificates
# the cron job should be like this:
# certbot renew --deploy-hook /usr/local/bin/update-openvpn-certs.sh
$DOMAIN = "YOUR_DOMAIN_NAME"
./sacli --key "cs.priv_key" --value_file "/etc/letsencrypt/live/$DOMAIN/privkey.pem" ConfigPut
./sacli --key "cs.cert" --value_file "/etc/letsencrypt/live/$DOMAIN/cert.pem" ConfigPut
./sacli --key "cs.ca_bundle" --value_file "/etc/letsencrypt/live/$DOMAIN/chain.pem" ConfigPut
@adamrunner
adamrunner / generate_crumbs_csv_service.rb
Created June 25, 2020 18:28
generates a CSV file where the first column is category titles in "crumbs" format for BR, second column is category IDs in "crumb_ids" format for BR.
class GenerateCrumbsCsvService
def self.perform
data = []
Category.where(listed: true, depth: 2).each do |category|
crumbs_id = [category.parent.parent._id.to_s, category.parent._id.to_s, category._id.to_s].join("|")
crumbs = [category.parent.parent.title, category.parent.title, category.title].join("|")
data.push([crumbs, crumbs_id])
end
CSV.open("/tmp/crumbs.csv", "w") do |csv|
@adamrunner
adamrunner / export_orders_promo_info_csv.rb
Last active July 8, 2019 22:47
Exports some order and promotion data to a CSV
def export_orders_promo_info_csv(start_date, end_date)
# start_date and end_date params should be Date objects
rows = []
rows << ["order_number", "status", "sub_total", "total", "discount", "promotion_code"]
Order::History.where(order_number: /^WO/, finalized_at: start_date..end_date).each do |order|
row = []
row << order.order_number
row << order.status
row << order.final_sub_total
row << order.final_total
@adamrunner
adamrunner / sync_updates_design.rb
Created April 24, 2019 19:36
pseudo code for the sync_updates implementation for updating multiple models via background job workers when referencing records change.
sync_updates to: ProductGroup::Dimension::Option, with: DimensionOption::SyncWorker, fields: [:all], after: []
sync_updates to: Product, # with: Admin::Data::SyncWorker
perform(source_class, dest_class, source_id, fields)
# finds all types of to models that contain the source_id
# e.g. Products that embed property_ids
# e.g. ProductGroup::Dimension::Option that have property_id of XXX
# enqueues individual update jobs for each record update, using sidekiq batch
ProductGroup.where("dimensions.options.property_id" => property_id)
@adamrunner
adamrunner / fix_filesytem_ownership.sh
Last active December 24, 2018 16:37
use these commands to fix file system permissions separately for files and directories
find . -type d -exec chmod 0700 '{}' \;
find . -type f -exec chmod 0600 '{}' \;
@adamrunner
adamrunner / webpack.config.asset-example.js
Created June 10, 2018 17:44
Example webpack config file for adding asset processing, allows import of CSS, Fonts, Data
// Webpack Config File
// Allows import of:
// CSS styles
// Fonts
// CSV/TSV data
// XML data
const path = require('path');
module.exports = {
class Mongoid::Migration
# renames a collection in mongodb, can be told to drop the target collection first
def self.rename_collection(old_name, new_name, drop_target=false)
client = Mongoid::Clients.default
current_db = client.database
admin_db = Mongo::Database.new(client, Mongo::Database::ADMIN, current_db.options)
admin_db.command(renameCollection: "#{current_db.name}.#{old_name}",
to: "#{current_db.name}.#{new_name}",
dropTarget: drop_target)
end
@adamrunner
adamrunner / send_temp.sh
Created August 6, 2017 03:00
tiny little bash script that runs on a cron job to pull the temperature from a SI7021 sensor on my C.H.I.P
#!/bin/bash
OUTPUT=`/usr/local/bin/si | grep -Po '(?<=Fahrenheit : ).+?(?=F)'`
CMD="mosquitto_pub -h temp.adamrunner.com -t outTopic -m ESP_E2106F,${OUTPUT}"
`$CMD`
@adamrunner
adamrunner / sidekiq-staging.conf
Created April 26, 2017 04:11
sidekiq staging configuration file for ubuntu upstart
# Sidekiq Preview/Staging Background worker
# sudo initctl sidekiq-staging {start, stop, restart}
#
description "Staging/Preview Sidekiq Background Worker"
# This script is not meant to start on bootup, workers.conf
# will start all sidekiq instances explicitly when it starts.
#start on runlevel [2345]
#stop on runlevel [06]
/* interrupt routine for Rotary Encoders
The average rotary encoder has three pins, seen from front: A C B
Clockwise rotation A(on)->B(on)->A(off)->B(off)
CounterCW rotation B(on)->A(on)->B(off)->A(off)
and may be a push switch with another two pins, pulled low at pin 8 in this case