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 / cartesian_product.cr
Created January 10, 2019 15:00
cartesian product example in Ruby, Python and Crystal
a = (1..2).to_a
b = (1..7).to_a
c = (1..144).to_a
d = (1..37).to_a
e = (1..28).to_a
f = (1..12).to_a
g = (1..16).to_a
result = Array(Array(Int32)).new
Array.each_product([a, b, c, d, e, f, g]) do |x|
@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 / nodeRest.js
Last active October 2, 2017 09:50
Sequelize, Restify & Epilouge with PostGres
const Sequelize = require('sequelize'),
epilogue = require('epilogue'),
restify = require('restify'),
passwordHash = require('password-hash');
// Define your models
const database = new Sequelize('whateverDatabase', 'rootUser', 'rootPassword', {
host: 'localhost',
dialect: 'postgres',
});
@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
@herrkessler
herrkessler / native-fonts.sass
Last active August 30, 2017 15:05
Native font stack from bootstrap 4 reboot
$font-family-sans-serif: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif !default
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.js
Created August 15, 2017 11:12
simple node async / await multiple requests with axios
const axios = require('axios');
const locations = ['London', 'San Francisco', 'Tokyo', 'Berlin'];
const apiURL = 'http://api.openweathermap.org/data/2.5/weather';
const token = 'xxxxx';
const logPosts = async () => {
try {
let allLocations = locations.map(town => axios(`${apiURL}?q=${town}&APPID=${token}`));
let weather = await Promise.all(allLocations);
@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
});
}