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
@erming
erming / rgb.js
Last active August 29, 2015 14:10
rgb.js
function rgb(hex) {
hex = hex.replace("#", "");
if (hex.length == 3) {
var original = hex;
hex = "";
for (var i = 0; i < 3; i++) {
hex += original.charAt(i) + original.charAt(i);
}
} else if (hex.length != 6) {
return;
@erming
erming / random.js
Created November 26, 2014 13:02
random.js
function random(seed) {
var x = Math.sin(seed);
if (x < 0) {
return x - (-1);
} else {
return x;
}
}
@erming
erming / wordpress
Created November 10, 2014 10:19
Nginx config for multisite rewrite
if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^(/[^/]+)?(/wp-.*) $2 last;
rewrite ^(/[^/]+)?(/.*\.php) $2 last;
}
@erming
erming / capitalize.js
Last active August 29, 2015 14:03
Capitalize the first letter of the string.
// Capitalize the first letter of the string.
function capitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
// Extend native String object.
String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
}
@erming
erming / Gruntfile.js
Created June 25, 2014 18:34
Auto-generating JSDoc with Grunt
module.exports = function(grunt) {
grunt.initConfig({
watch: {
scripts: {
files: ["src/*.js"],
tasks: ["default"]
}
}
});
grunt.loadNpmTasks("grunt-contrib-watch");
/**
* Generate hex color code from a string.
*
* @param {String} string
* @return {String}
*/
$.string_to_color("");
/**
* Set one or more CSS properties for the set
@erming
erming / escape.js
Created June 3, 2014 16:52
escape.js
function escape(text) {
var e = {
"<": "&lt;",
">": "&gt;"
};
return text.replace(/[<>]/g, function (c) {
return e[c];
});
}
@erming
erming / mustache.render.js
Last active August 29, 2015 14:02
Render helper with template caching.
// Requires:
// <script src="mustache.js"></script>
// Template cache
var tpl = [];
//
// Render templates.
//
// Usage:
@erming
erming / overflow-scrolling.html
Last active August 29, 2015 14:02
-webkit-overflow-scrolling
<!doctype html>
<html>
<head>
<title>-webkit-overflow-scrolling</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no">
<style>
@erming
erming / last.js
Created May 5, 2014 23:47
last.js
// Get the last word of a string.
function last(str) {
return str.trim().split(" ").pop();
}