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 / gen_cert.sh
Created March 31, 2016 18:26
bash script to generate a self signed certificate for development use
#!/bin/bash
# Bash shell script for generating self-signed certs. Run this in a folder, as it
# generates a few files. Large portions of this script were taken from the
# following artcile:
#
# http://usrportage.de/archives/919-Batch-generating-SSL-certificates.html
#
# Additional alterations by: Brad Landers
# Date: 2012-01-27
@adamrunner
adamrunner / https_server_nginx.conf
Last active November 18, 2023 18:27
Server Directive for Nginx, redirect from HTTP to HTTPS.
#NOTE: Redirect to HTTPS
server {
listen 80;
listen [::]:80;
server_name example.com;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl;
@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 / git_clean_remote
Created January 17, 2013 21:58
clear all old remote branches
git remote prune origin
git branch -r --merged | grep origin | grep -v '>' | grep -v master | grep -v dev | xargs -L1 | awk '{sub(/origin\//,"");print}' | xargs git push origin --delete
@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