Skip to content

Instantly share code, notes, and snippets.

View herrkessler's full-sized avatar
:octocat:

Sebastian Kessler herrkessler

:octocat:
View GitHub Profile
@herrkessler
herrkessler / Dockerfile
Created February 26, 2018 10:46 — forked from dogweather/Dockerfile
Docker dev environment for Ruby on Rails
# Ruby on Rails Development Environment
FROM ruby:2.5.0
# Set up Linux
RUN apt-get update
RUN apt-get install -y build-essential inotify-tools libpq-dev nodejs postgresql-client
WORKDIR /app
EXPOSE 3000
@herrkessler
herrkessler / .railsrc
Created February 20, 2018 11:50 — forked from qbantek/.railsrc
Command line options for ` rails new --help ` (Rails 5.1.4). Useful for planning new Ruby on Rails app. 'Where can I find options for “rails new” command?'
--skip-active-record
--skip-test-unit
--skip-system-test
--skip-turbolinks
--skip-spring
--skip-keeps
--skip-coffee
--skip-action-cable
--skip-action-mailer
--skip-listen
@herrkessler
herrkessler / dynamic-critical-path-css.md
Created November 9, 2017 10:54 — forked from taranda/dynamic-critical-path-css.md
Dynamically Add Critical CSS to Your Rails App

Dynamically Add Critical CSS to Your Rails App

Optimizing the delivery of CSS is one way to improve user experience, load speed and SEO of your web app. This involves determining the "critical path CSS" and embeding it into the html of your page. The rest of the CSS for the site is loaded asynchronously so it does not block the rendering of your "above the fold" content. This Gist will show you how to dynamically generate critical path CSS for your Rails app.

In this example we will use the mudbugmedia/critical-path-css gem.

Prerequisites

You will need to set up caching and Active Job in your Rails app. I recommend using a thread-safe background job manager like resque.

@herrkessler
herrkessler / aes_enc_dec.php
Created August 30, 2017 15:04 — forked from turret-io/aes_enc_dec.php
AES encryption/decryption in PHP
<?php
// DEFINE our cipher
define('AES_256_CBC', 'aes-256-cbc');
// Generate a 256-bit encryption key
// This should be stored somewhere instead of recreating it each time
$encryption_key = openssl_random_pseudo_bytes(32);
// Generate an initialization vector
// This *MUST* be available for decryption as well
async function supportsWebp() {
if (!self.createImageBitmap) return false;
const webpData = 'data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA=';
const blob = await fetch(webpData).then(r => r.blob());
return createImageBitmap(blob).then(() => true, () => false);
}
addEventListener('install', event => {
event.waitUntil(async function() {
@herrkessler
herrkessler / async-await.js
Created July 12, 2017 08:14 — forked from wesbos/async-await.js
Simple Async/Await Example
// 🔥 Node 7.6 has async/await! Here is a quick run down on how async/await works
const axios = require('axios'); // promised based requests - like fetch()
function getCoffee() {
return new Promise(resolve => {
setTimeout(() => resolve('☕'), 2000); // it takes 2 seconds to make coffee
});
}
@herrkessler
herrkessler / dom-helper.js
Created April 5, 2017 06:49 — forked from SitePointEditors/dom-helper.js
Mini jQuery, sort of.
/**
* A collection of helper prototype for everyday DOM traversal, manipulation,
* and event binding. Sort of a minimalist jQuery, mainly for demonstration
* purposes. MIT @ m3g4p0p
*/
window.$ = (function (undefined) {
/**
* Duration constants
* @type {Object}
@mixin for-phone-only {
@media (max-width: 599px) { @content; }
}
@mixin for-tablet-portrait-up {
@media (min-width: 600px) { @content; }
}
@mixin for-tablet-landscape-up {
@media (min-width: 900px) { @content; }
}
@mixin for-desktop-up {
mixin img
-
attributes.src = attributes.src || ''
attributes.alt = attributes.alt || ""
if(!attributes.adaptive && !attributes.webp && !attributes.retina)
img(src = attributes.src, class = attributes.class, alt = attributes.alt)
else
-
var chunks = attributes.src.split('.')
@herrkessler
herrkessler / ChromeExtensionGulp.js
Created August 24, 2016 11:37 — forked from TravelingTechGuy/ChromeExtensionGulp.js
Gulp file for building a Chrome Extension
'use strict';
//npm install gulp gulp-minify-css gulp-uglify gulp-clean gulp-cleanhtml gulp-jshint gulp-strip-debug gulp-zip --save-dev
var gulp = require('gulp'),
clean = require('gulp-clean'),
cleanhtml = require('gulp-cleanhtml'),
minifycss = require('gulp-minify-css'),
jshint = require('gulp-jshint'),
stripdebug = require('gulp-strip-debug'),