Skip to content

Instantly share code, notes, and snippets.

[role=navigation] {
margin-bottom: 1px;
}
[role=main] > div {
background-color: white;
border-left: 1px solid #d1d1d1;
border-right: 1px solid #d1d1d1;
box-sizing: border-box;
margin: 0 auto;
padding: 1em;
@Sleavely
Sleavely / POT.patch
Last active August 29, 2015 14:02
POT Minimap patch
From 3ec96e871d2e561faeef82524ed91bb98698f6a1 Mon Sep 17 00:00:00 2001
From: Joakim Hedlund
Date: Thu, 12 Jun 2014 18:44:52 +0200
Subject: [PATCH] Parse and tuck away minimap colors
---
app/libraries/POT/OTS_ItemsList.php | 68 ++++++++++++++++++++++++++++++++-----
1 file changed, 59 insertions(+), 9 deletions(-)
diff --git a/app/libraries/POT/OTS_ItemsList.php b/app/libraries/POT/OTS_ItemsList.php
@Sleavely
Sleavely / arrayFromHTMLInput.php
Last active August 29, 2015 14:10
Dealing with dynamic amounts of fields in HTML forms usually means you get your data in a very foreach-unfriendly manner. This helper function is meant to address that. Input and output are presented in JSON because I like it better. Actual results are PHP. YMMV
<?php
/**
* Helper function to reformat arrays.
* @see https://gist.github.com/Sleavely/2c1aa7ba13da80dfeb43
*
* @param array $source
* The multidimensional array where each input field is an array
* @param array $arrays
* A list of which keys to include in the output
<?php
$errand = foo();
$order = bar();
// Email the customer a receipt
$mail = Mail::send('returns.emails.approved', array('data' => 'to', 'the' => 'view'), function($message) use ($errand, $order)
{
// The "use" keyword allows us to access external variables in our anonymous function
@Sleavely
Sleavely / deploy.sh
Last active August 29, 2015 14:21
Simple Magento deployment
#!/bin/sh
cd ~/www/magento
# Pull main repo
git pull --no-edit origin master
# Update submodules
git submodule update --recursive
git submodule update --init --recursive
@Sleavely
Sleavely / klarnatag.js
Created June 21, 2012 11:27
Building Klarna-style underlines
/**
Requires jQuery.
Built, with love, by Joakim Hedlund <joakim.hedlund@klarna.com>
*/
jQuery.fn.lastLineWidth = function(text){
var $this = jQuery(this),
$tmpHtml = jQuery('<span style="postion:absolute;width:auto;left:-9999px"></span>');
var containerWidth = $this.width(), //width of the container (e.g. <h1>)
@Sleavely
Sleavely / index.html
Created October 13, 2012 16:26
OTMap - CSS-zoom
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="sv-SE"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width">
<title>Zoomable OTMap</title>
@Sleavely
Sleavely / dynamic-logos.html
Created October 13, 2012 22:22
Inserting images safely with Javascript. See console for mouseover
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="sv-SE"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width">
<title>Klarna dynamic logos</title>
@Sleavely
Sleavely / ajaxBefore.js
Last active December 19, 2015 07:09
Run an AJAX call before leaving the page through a link.
jQuery(".my-awesome-link-class").one('click', function(event){
var $this = jQuery(this);
//no need to delay when the link opens in a new window
if (!$this.attr("target") && !event.ctrlKey && !event.shiftKey && !event.metaKey) {
event.preventDefault();
var newHref = this.href;
//the below is pseudo-code
jQuery.ajax({
<?php
function validatePNumber($pnumber) {
// reference: http://en.wikipedia.org/wiki/National_identification_number#Finland
//initial format thingy
$pnumber = strtoupper($pnumber);
if(!preg_match('/^([0-9]{6})(\-|\+|A)?([0-9]{3})([0-9A-Y])$/', $pnumber, $matches)) return false;
//loop through each character of $matches[1].$matches[3] and sum them up