Skip to content

Instantly share code, notes, and snippets.

@advitum
advitum / humanFileSize.php
Created July 17, 2014 12:59
Makes file size human-readable
<?php
function humanFileSize($size, $german = true) {
$fileSizePrefixes = array('k', 'M', 'G', 'T', 'P');
$size = intval($size);
$prefix = -1;
while($size > 1024 / 5 && $prefix < count($fileSizePrefixes) - 1) {
$size /= 1024;
@advitum
advitum / drag-and-drop-sortable-tables.markdown
Last active August 29, 2015 14:04
Sorting tables with drag and drop

Sorting tables with drag and drop

We start with a simple HTML table:

<table class="sortable">
	<tbody>
		<tr data-id="1">
			<td>Some content</td>
@advitum
advitum / grid.scss
Last active August 29, 2015 14:04
SCSS grid system using box-sizing
$columnCount: 12;
$columnWidth: 64px;
$gutterWidth: 20px;
@mixin clear {
&::after {
content: "";
width: 100%;
height: 0px;
display: block;
@advitum
advitum / google-map.js
Last active August 29, 2015 14:05
How to display a google map.
//http://maps.google.com/maps/api/js?sensor=false
var position = [xxx, xxx];
$('#map').each(function() {
var map;
var latlng = new google.maps.LatLng(position[0], position[1]);
var center = new google.maps.LatLng(position[0], position[1]);
map = new google.maps.Map($(this).get(0), {
@advitum
advitum / cake-backend.markdown
Last active August 29, 2015 14:07
Quick backend in CakePHP

Add a quick backend to CakePHP

Add to config/core.php:

<?php
Configure::write('Routing.prefixes', array('admin'));
@advitum
advitum / grid.scss
Last active August 29, 2015 14:07
Fluid SCSS Grid
$gridColumnCount: 12;
$gridGutterWidth: 40px;
$gridMaxWidth: 1400px;
@mixin clearfix {
&::after {
clear: both;
content: "";
display: block;
height: 0px;
@advitum
advitum / home.php
Created February 9, 2015 09:21
Display the pages content on a WP custom home-page.
<?php
global $post;
$page = get_option('page_for_posts');
$post = get_page($page);
setup_postdata($post);
?>
@advitum
advitum / createSvgElement.js
Created July 24, 2015 14:09
Creating SVG elements with correct namespace.
function createSvgElement(tag, attributes) {
var element = document.createElementNS('http://www.w3.org/2000/svg', tag);
for(var k in attributes) {
element.setAttribute(k, attributes[k]);
}
return element;
}
@advitum
advitum / cookiePolicy.js
Last active August 29, 2015 14:26
Alert the user that this website is using cookies.
(function(messageContent) {
var cookieName = 'cookiePolicyHide';
function hideMessage() {
message.parentNode.removeChild(message);
document.cookie = cookieName + '=1;path=/';
}
function messageHidden() {
var cookies = document.cookie.split(';');
for(var index = 0; index < cookies.length; index++) {
while(cookies[index].charAt(0) === ' ') {
@advitum
advitum / datepicker.js
Created September 7, 2015 12:15
Very simple datepicker using jQuery.
function Datepicker($input) {
var datepicker = this;
datepicker.$input = $input;
$input.on('click', function(event) {
event.stopPropagation();
}).on('focus', function() {
datepicker.open();
});