Skip to content

Instantly share code, notes, and snippets.

View hising's full-sized avatar

Mattias Hising hising

View GitHub Profile
@hising
hising / git.migrate
Created April 1, 2017 13:42 — forked from niksumeiko/git.migrate
Moving git repository and all its branches, tags to a new remote repository keeping commits history
#!/bin/bash
# Sometimes you need to move your existing git repository
# to a new remote repository (/new remote origin).
# Here are a simple and quick steps that does exactly this.
#
# Let's assume we call "old repo" the repository you wish
# to move, and "new repo" the one you wish to move to.
#
### Step 1. Make sure you have a local copy of all "old repo"
### branches and tags.
@hising
hising / nodelist.js
Last active May 3, 2017 10:15
NodeList to Array Functions (for better code readability)
export const nodeListToArray = (nodeList) => {
return Array.prototype.slice.call(nodeList);
};
export const querySelectorAllArray = (selector) => {
return nodeListToArray(document.querySelectorAll(selector));
};
export const objectAsArray = (obj) => {
return Object.keys(obj);
@hising
hising / handleError.php
Last active May 6, 2017 10:54
Slim 3 Middleware for routing route triggered errors to standard Error page
<?php
$app->add(function ($request, $response, $next) use ($container) {
// First execute anything else
$response = $next($request, $response);
// Check if the response should render a 404
if ($response->getStatusCode() === 404 && $response->getBody()->getSize() === 0) {
// A 404 should be invoked
$handler = $container['notFoundHandler'];
return $handler($request, $response);
@hising
hising / Cache.php
Last active February 5, 2020 14:36
Slim 2 Memcached Cache Middleware
<?php
namespace Doon\Middleware;
use Memcached;
class Cache extends \Slim\Middleware {
protected $memcached, $settings, $ttl;
public function __construct($settings)
@hising
hising / ui-gradients.css
Created May 17, 2017 16:46
UI Gradients
.sour-tropical-gradient { background: -webkit-linear-gradient(90deg, #FD6F46 10%, #FB9832 90%); /* Chrome 10+, Saf5.1+ */ background: -moz-linear-gradient(90deg, #FD6F46 10%, #FB9832 90%); /* FF3.6+ */ background: linear-gradient(90deg, #FD6F46 10%, #FB9832 90%); /* W3C */ }
.subtle-gray-gradient { background: -webkit-linear-gradient(90deg, #dee1e1 10%, #f4f4f4 90%); /* Chrome 10+, Saf5.1+ */ background: -moz-linear-gradient(90deg, #dee1e1 10%, #f4f4f4 90%); /* FF3.6+ */ background: linear-gradient(90deg, #dee1e1 10%, #f4f4f4 90%); /* W3C */ }
.epic-bluegreen-gradient { background: -webkit-linear-gradient(90deg, #01a99c 10%, #0698b1 90%); /* Chrome 10+, Saf5.1+ */ background: -moz-linear-gradient(90deg, #01a99c 10%, #0698b1 90%); /* FF3.6+ */ background: linear-gradient(90deg, #01a99c 10%, #0698b1 90%); /* W3C */ }
.golden-face-gradient { background: -webkit-linear-gradient(90deg, #8e7a3f 10%, #b09a51 90%); /* Chrome 10+, Saf5.1+ */ background: -o-linear-gradient(90deg, #8e7a3f 10%, #b09a51 90%); /* Opera 11.
@hising
hising / bots.json
Created May 22, 2017 21:20
Bots pattern JSON
{
"bots": [
"Googlebot",
"DotBot",
"AhrefsBot",
"MJ12bot",
"Slurp",
"spbot",
"bingbot",
"SemrushBot",
@hising
hising / Optionals.php
Created May 27, 2017 08:28 — forked from miguelsaddress/Optionals.php
A take on optionals in PHP
<?php
error_reporting(E_ALL ^ E_NOTICE);
abstract class Option {
protected $value;
public function __construct($value) {
if (isset($value)) return some($value);
else return none();
}
@hising
hising / Template.php
Last active June 7, 2017 18:04
Simple PHP template class that takes one-level-deep assoc arrays and replaces content in template
<?php
namespace Bstd;
/**
* Class Template
* @package Bstd
*/
class Template {
/**
* @var string
@hising
hising / incognito.js
Created June 14, 2017 15:51
Check if window is incognito
var fs = window.RequestFileSystem || window.webkitRequestFileSystem;
if (!fs) {
console.log("check failed?");
} else {
fs(window.TEMPORARY,
100,
console.log.bind(console, "not in incognito mode"),
console.log.bind(console, "incognito mode"));
}
@hising
hising / visible.js
Last active June 14, 2017 15:58
Check if current tab is visible
(function() {
var hidden = "hidden";
// Standards:
if (hidden in document)
document.addEventListener("visibilitychange", onchange);
else if ((hidden = "mozHidden") in document)
document.addEventListener("mozvisibilitychange", onchange);
else if ((hidden = "webkitHidden") in document)
document.addEventListener("webkitvisibilitychange", onchange);