Skip to content

Instantly share code, notes, and snippets.

View dommmel's full-sized avatar
💭
That worked!

Dominik dommmel

💭
That worked!
View GitHub Profile
@dommmel
dommmel / README.md
Last active August 29, 2015 14:28
Jekyll YouTube Plugin.

Takes a Youtube URL and generates a responsive snippet

Usage

 {% youtube "https://www.youtube.com/watch?v=ho8-vK0L1_8" %}

or using variables/front matter

@dommmel
dommmel / Coce.gs
Created August 2, 2015 13:28
Google Apps Script to upload and import a CSV File into a Google Spreadsheet
// http://stackoverflow.com/questions/11273268/script-import-local-csv-in-google-spreadsheet
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var csvMenuEntries = [{name: "Upload CSV file", functionName: "doGet"}];
ss.addMenu("CSV", csvMenuEntries);
}
function doGet(e) {
var app = UiApp.createApplication().setTitle("Upload CSV to Sheet");
@dommmel
dommmel / tracking_url.js
Last active August 29, 2015 14:23
Unbounce Cross Domain External Tracking
// On external pages (same domain) you need to grab the cookie
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}
var url = "http://t.unbounce.com/trk?v=" + getCookie('ubvt') + "&g=convert"
// On the unbounce page itself you have direct access
var url = "http://t.unbounce.com/trk?v=" + ub.page.visitorId + "&g=convert"
@dommmel
dommmel / guest_author_with_title.php
Last active August 29, 2015 14:05
Wordpress module to add and display a guest author's name and title
<?php
/**
*
* Add ability to add guest authors
*/
function myblog_guest_author_name( $original_name ) {
if (in_the_loop()) {
$guest_name = get_post_meta( get_the_ID(), 'guest_author_name', true );
return ( $guest_name ) ? $guest_name : $original_name;
@dommmel
dommmel / routes.rb
Last active August 29, 2015 14:04
rails canonical host
if ENV['CANONICAL_HOST']
constraints(:host => Regexp.new("^(?!#{Regexp.escape(ENV['CANONICAL_HOST'])})")) do
match "/(*path)" => redirect { |params, req| "http://#{ENV['CANONICAL_HOST']}/#{params[:path]}" }, via: [:get, :post]
end
end
@dommmel
dommmel / dokku-pg-backup.sh
Last active September 16, 2020 08:03
dokku postgres backup cronjob (using https://github.com/Kloadut/dokku-pg-plugin)
#! /bin/bash
# directory to save backups in, must be rwx by postgres user
BASE_DIR="/var/backups/postgres"
YMD=$(date "+%Y-%m-%d")
DIR="$BASE_DIR/$YMD"
mkdir -p $DIR
cd $DIR
# make database backup
@dommmel
dommmel / compare_yml.rake
Created July 23, 2014 08:31
Rake task to compare keys in Rails locale.yml files
desc "TODO"
task :compare_yml, [:locale1, :locale2] => :environment do |t, args|
LOCALE_1 = "config/locales/#{args[:locale1]}.yml"
LOCALE_2 = "config/locales/#{args[:locale2]}.yml"
require 'yaml'
def flatten_keys(hash, prefix="")
keys = []
hash.keys.each do |key|
@dommmel
dommmel / Vagrantfile
Last active August 29, 2015 14:02
Setup Dokku on Vagrant - easy!
# -*- mode: ruby -*-
# vi: set ft=ruby :
$script = <<SCRIPT
export HOST_USER=$1
apt-get update -y && apt-get -y install git
# Install Dokku
wget -qO- https://raw.github.com/progrium/dokku/v0.2.3/bootstrap.sh | DOKKU_TAG=v0.2.3 bash
@dommmel
dommmel / server.js
Created May 24, 2014 14:35
secure express 4 boilerplate using (tags: mincer, sass, coffeescript, bootstrap, cookie-session, csrf, swig)
var express = require('express')
, path = require('path')
, helmet = require('helmet')
, csrf = require('csurf')
, cookieParser = require('cookie-parser')
, bodyParser = require('body-parser')
, cookieSession = require('cookie-session')
, methodOverride = require('method-override')
, compress = require('compression')
, mincer = require('mincer')
@dommmel
dommmel / express_4_basic_auth.js
Last active August 29, 2015 14:01
Express 4 - Basic HTTP authentication
function authenticate(req, res, next) {
var auth = require('basic-auth');
var user = auth(req);
if (user === undefined || user['name'] !== 'user' || user['pass'] !== 'pass') {
res.statusCode = 401;
res.setHeader('WWW-Authenticate', 'Basic realm="Bitte anmelden!"');
res.end('Unauthorized');
} else {
next();
}