Skip to content

Instantly share code, notes, and snippets.

View hendricius's full-sized avatar

Hendrik Kleinwaechter hendricius

View GitHub Profile
container_commands:
01_fix_static_cors:
command: "/tmp/fix_static_cors.sh"
files:
"/tmp/fix_static_cors.sh":
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash
@hendricius
hendricius / tutorial.md
Last active October 23, 2016 12:39
Starting Sidekiq via upstart on Ubuntu using rbenv

The Sidekiq service config. Goes into /etc/init/sidekiq.conf

# /etc/init/sidekiq.conf - Sidekiq config

# This example config should work with Ubuntu 12.04+.  It
# allows you to manage multiple Sidekiq instances with
# Upstart, Ubuntu's native service management tool.
#
# See workers.conf for how to manage all Sidekiq instances at once.
@hendricius
hendricius / parallel_curl.sh
Last active January 5, 2016 20:36 — forked from CMCDragonkai/parallel_curl.sh
Bash: GNU Parallel with Curl
# do it once
seq 1 | parallel -n0 "curl http://localhost:3000"
# do it twice
seq 2 | parallel -n0 "curl --header 'Connection: keep-alive' http://localhost:3000"
# do it 4 times, but at 2 a time
seq 10000 | parallel -n0 -j10 "curl --header 'Connection: keep-alive' https://prelive.tripl.de"
```
namespace :db do
desc "Populate database"
task :populate => :environment do
[Brand].each(&:delete_all)
filename = File.join Rails.root, "databases/brands.csv"
counter = 0
CSV.foreach(filename, headers: true) do |row|
p row
@hendricius
hendricius / pdf_printer.rb
Created January 20, 2015 17:25
A service that makes printing a PDF with pdfkit easier.
# Convert html to a PDF file.
class PdfPrinter
include Virtus.model
attribute :html, String
attribute :file_name, String, default: ->(printer, attribute) { "#{SecureRandom.hex(20)}-#{DateTime.now.to_i}.pdf"}
attribute :store_location, String, default: "/tmp"
attribute :temp_css_location, String, default: "/tmp"
attribute :wkhtmltopdf_parameters, Hash, default: {
"--footer-right" => "[page]/[toPage]",
"--footer-font-size" => 8
CSS:
.hidden-in-print {
display: none; }
body {
background: white; }
.main-container {
background: white;
# UI
a ng-href="/vessels?angular_filter[code]={{ sched.code }}"
| {{sched.code}}
# ApplicationController
before_filter do
gon.app_name = "Docking"
gon.angular_filter = params[:angular_filter] if params[:angular_filter]
end
@hendricius
hendricius / gist:b912db612770cdcd26c7
Created May 9, 2014 16:37
Join creating many results
# Doing the count by hand vs count from the join https://www.dropbox.com/s/sms6mot4ly6b54o/Screenshot%202014-05-09%2018.33.09.png
@shopping_setups = ShoppingSetup.joins(:company).
joins("LEFT JOIN products on companies.id = products.company_id").
joins("LEFT JOIN categories on companies.id = categories.company_id").
select("shopping_setups.*").
select("COUNT(products.company_id) AS products_count").
select("COUNT(categories.company_id) AS categories_count").
group("shopping_setups.id, companies.id, products.company_id, categories.company_id")
require 'git'
require 'pry'
require 'date'
# Pretty print git commits for easy parsing to zeitkit
# [2014-01-12]
#
# First commit: 2014-01-12 15:55
# * make functions clearer
@hendricius
hendricius / gist:9914004
Last active August 29, 2015 13:57
Site verification example

Request:

https://www.googleapis.com/siteVerification/v1/token?fields=token&key={{my_key}}

Headers:

access-control-allow-origin →chrome-extension://fdmmgilgnpjigdojojpjoooidkmcomcm
access-control-expose-headers →Content-Encoding,Content-Length,Content-Type,Date,Server,WWW-Authenticate

alternate-protocol →443:quic