Skip to content

Instantly share code, notes, and snippets.

View herrkessler's full-sized avatar
:octocat:

Sebastian Kessler herrkessler

:octocat:
View GitHub Profile
@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 {
@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 picture(path, name, type)
picture
each val in type
source(srcset=path + "/" + name + "." + val type="image/" + val)
img(src=path + "/" + name + ".jpg" alt=name)
+picture('path/to', 'image', ['jpg','webp'])
// Compiles to
//------------------------
@herrkessler
herrkessler / Gulpfile.js
Last active April 11, 2017 07:32
Gulp static compiler
'use strict';
var postcss = require('gulp-postcss');
var gulp = require('gulp');
var autoprefixer = require('autoprefixer');
var cssnano = require('cssnano');
var sass = require('gulp-sass');
var include = require('gulp-include');
var concat = require('gulp-concat');
var browserSync = require('browser-sync').create();
@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 / 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);
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 / 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
@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 / 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',
});