Skip to content

Instantly share code, notes, and snippets.

@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
<?php
function correctYYMMDD($input){
$input = substr($input, 0, 6);
//is it already in correct format?
if(preg_match('/[0-9][0-9](1[0-2]|0[1-9])([0-2][0-9]|3[01])/', $input)) return $input;
//let's reverse it.
$rev = array();
$rev['yy'] = substr($input, 4, 2);
<?php
protected static function validatePNumber($pnumber) {
/* Check valid form (existing month and day) */
if (!preg_match("/^[0-9]{2}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))[0-9]{4}$/", $pnumber)) return false;
/* Calculate check sum and check wether or not the control digit is correct */
$sum = 0;
$x = 0;
for ($i = 0; $i < 10; $i++) {
@Sleavely
Sleavely / command.js
Last active December 27, 2015 11:59
Backtick - Prettify
(function a() {
var a, b;
Array.prototype.forEach.call(document.querySelectorAll("pre"), function (a) {
a.className = "prettyprint linenums"
}), a = document.createElement("script"), a.onload = function () {
prettyPrint()
}, a.src = "https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?skin=sunburst", document.body.appendChild(a)
})();
@Sleavely
Sleavely / command.js
Last active January 1, 2016 04:49 — forked from JoelBesada/README.md
Premailer bookmarklet
(function(){
document.body.appendChild(document.createElement('script')).src='http://premailer.dialect.ca/inc/bookmarklet-1.0.js';
})();
<?php
print '<meta charset="utf8" /><pre>';
require_once('oauth.php');
$settings = array(
'oauth_access_token' => "",
'oauth_access_token_secret' => "",
'consumer_key' => "",
'consumer_secret' => ""
);