Skip to content

Instantly share code, notes, and snippets.

View crohr's full-sized avatar
➡️
Checkout PullPreview.com and RunsOn.com

Cyril Rohr crohr

➡️
Checkout PullPreview.com and RunsOn.com
View GitHub Profile
@crohr
crohr / cloudformation-dynamic-cidr.yaml
Created January 19, 2024 10:21
Cloudformation template to get a dynamically generated CIDR block for subnets based on the selected availability zone
Mappings:
Networking:
AzSuffixToIndex:
1a: 0
1b: 1
1c: 2
1d: 3
1e: 4
1f: 5
1g: 6
@crohr
crohr / pullpreview.yml
Last active January 25, 2024 08:57
Example PullPreview workflow
# .github/workflows/pullpreview.yml
name: PullPreview
on:
# the schedule is optional, but helps to make sure no dangling resources are left when GitHub Action does not behave properly
schedule:
- cron: "30 2 * * *"
# optional, only use if you want to have an always-on branch
push:
branches:
- main
@crohr
crohr / ec2-user-data.sh
Last active November 30, 2023 13:39
ec2-user-data.sh
#!/bin/bash
set -e
set -o pipefail
KEYS="${KEYS:=crohr}"
mkdir -p /root/.ssh
chmod 0700 /root/.ssh
curl -L https://github.com/{$KEYS}.keys > /root/.ssh/authorized_keys
chmod 0600 /root/.ssh/authorized_keys
require 'erb'
require 'benchmark'
require 'ostruct'
require 'action_view'
require 'rails'
include ActionView::Helpers::TagHelper
include ActionView::Helpers::TextHelper
include ActionView::Helpers::UrlHelper
data = OpenStruct.new name: 'Sample', email: 'sample@mail.com', list: %w(one two three)
@output = ''
@crohr
crohr / postinstall.sh
Created November 24, 2015 16:27
Simple postinstall file for rails apps on https://packager.io
#!/bin/sh
set -e
CLI="my-app"
# if a DATABASE_URL is properly configured, then we can run migrations and web process
if $CLI config:get DATABASE_URL ; then
$CLI run rake db:migrate
$CLI scale web=1
combinator/
  docker-compose.yml
  README.md
  src/
    augur/
    concierge/
    openproject-saas/
    reeve/
 ...
@crohr
crohr / Dockerfile
Created July 23, 2015 13:37
Fully-working Dockerfile for a Rails app
FROM ruby:2.1
RUN apt-get update && apt-get install -y nodejs
RUN mkdir -p /usr/src/app
RUN useradd -d /usr/src/app -m app
RUN chown -R app /usr/src/app
RUN chown -R app /usr/local/bundle
USER root
@crohr
crohr / howto-stream-tmux-session-in-realtime-over-http.md
Last active January 22, 2024 08:25
Stream a tmux session in realtime over HTTP

On the server with tmux

Create a new tmux session:

tmux new-session -s my-session # launch `top`, `htop`, or anything that will regularly updates, then detach

Stream your session:

@crohr
crohr / README.md
Last active August 29, 2015 14:14
How to save buildpacks locally for use with pkgr

Clone buildpack(s) locally:

git clone --bare https://github.com/pkgr/heroku-buildpack-ruby.git \
  /tmp/heroku-buildpack-ruby.git

Save manifest with a list of buildpacks to use:

@crohr
crohr / mysql-db-convert.rb
Created December 2, 2014 10:40
Convert latin1 MySQL database to utf-8
require 'mysql2'
database_name = ENV.fetch('DATABASE') { "voicepublisher_development2" }
CLIENT = Mysql2::Client.new(host: "127.0.0.1", username: "user", password: "pass", database: database_name, encoding: "utf8")
def column_definition(schema, table, column)
sql = <<SQL
SELECT CONCAT(
CAST(COLUMN_NAME AS CHAR),