Skip to content

Instantly share code, notes, and snippets.

View erming's full-sized avatar
Tinkering.

Mattias Erming erming

Tinkering.
  • Software Contractor
  • Sweden
View GitHub Profile
function isJSON(str) {
if (typeof str !== "string") {
return false;
}
var char = str.charAt(0);
if (char != "[" && char != "{") {
return false;
}
try {
return typeof JSON.parse(str) === 'object';
@erming
erming / crontab
Last active February 13, 2019 20:46
@reboot screen -d -m ~/startup.sh
#!/bin/bash
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository ppa:ondrej/php
sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://ftp.ddg.lth.se/mariadb/repo/10.3/ubuntu bionic main'
curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
sudo apt-get -y update
@erming
erming / view.php
Created May 31, 2015 19:06
Minimal view engine
<?php
function View($file, array $args = []) {
extract($args);
ob_start();
if (file_exists($file)) {
include $file;
return ob_get_clean();
}
}
?>
@erming
erming / register_post_type.php
Created April 1, 2015 08:43
WordPress register post type
<?php
register_post_type("example", [
"labels" => [
"name" => "Examples",
"singular_name" => "Example"
],
"show_ui" => true,
"supports" => [
"title",
"editor",
@erming
erming / path.php
Created April 1, 2015 08:28
WordPress path helper
<?php
function path($file = "") {
return get_template_directory_uri() . "/$file";
}
?>
String.prototype.wrap = function(str) {
return "" + str + this + str;
};
@erming
erming / square.html
Last active October 25, 2016 20:25
Responsive square <div> with CSS only
<div class="square">
<div class="square-content">
Hello world!
</div>
</div>
@erming
erming / module.js
Created November 30, 2014 16:28
Export to node and the browser
var Example =
typeof window === "undefined" ? this
: window.Example = {};
Example.foo = function() {
return 1;
};
@erming
erming / hex.js
Created November 26, 2014 15:05
hex.js
function hex(r, g, b) {
var hex = "#";
if (Array.isArray(r)) {
var rgb = r;
r = rgb[0];
g = rgb[1];
b = rgb[2];
}
var rgb = [
r || 0,