Skip to content

Instantly share code, notes, and snippets.

@nekman
nekman / swedish-social-security-regexp.js
Created July 1, 2011 09:33
Simple JS regexp for swedish social security number
/*NOTE:
This is just a simple pattern check, so: /^\d{6,8}[-|(\s)]{0,1}\d{4}$/.test("000000 0000") // true
/^\d{6,8}[-|(\s)]{0,1}\d{4}$/.test('195505055555'); // true
/^\d{6,8}[-|(\s)]{0,1}\d{4}$/.test('19550505-5555'); // true
/^\d{6,8}[-|(\s)]{0,1}\d{4}$/.test('550505-5555'); // true
/^\d{6,8}[-|(\s)]{0,1}\d{4}$/.test('550505 5555'); // true
@nekman
nekman / keyValueCache.js
Created October 25, 2011 17:55
Simple javascript key/value cache
/*
cache.set(<key>, <value>)
cache.set({ <key1> : <value1>, <keyN> : <valueN> });
cache.get(<key>, <optional|defaultvalue>) => <value>
Example:
cache.set({ foo : 'bar' });
cache.get('foo'); //'bar'
@nekman
nekman / FilterExtentions.cs
Created December 2, 2011 13:03
C# Filter extensions
using System;
using System.Collections.Generic;
using System.Linq;
namespace Utils.Extensions
{
public static class FilterExtensions
{
/// <summary>
/// Remove null values from the collection.
@nekman
nekman / CollectionMapper.cs
Created December 2, 2011 17:19
C# collection mapper class
using System;
using System.Collections.Generic;
using System.Linq;
namespace Utils.Lab.Mapping
{
/// <summary>
/// Mapper class converts a collection with the given predicate.
/// </summary>
public class CollectionMapper
@nekman
nekman / Cache.cs
Created December 8, 2011 14:36
C# generic cache
using System;
using System.Collections.Generic;
namespace Cache
{
/// <summary>
/// Generic cache. Should be wrapped in a singelton.
/// - Some issues with reloading, see http://stackoverflow.com/questions/8403782/c-sharp-reload-singleton-cache/ for more info.
/// </summary>
@nekman
nekman / link.js
Created April 19, 2012 21:21
Simple hack, just to be able to right click a link and select "Save as" on Facebook.
@nekman
nekman / labs.arrayFind.js
Created June 19, 2012 21:11
Find items in an array.
/*!
I can have reinvented the wheel...But it is good to do so, just for the education :)
Anyway!
Finds a item in an array, by the given search string and/or matching function.
Usage:
------------------
/*!
Written for education purpose.
Could use Array.filter / Array.map instead.
Example:
//Returns an array with one object: {name:'foo'}
var result = { packages : [{name:'foo'}, {name:'bar'}, {name:'baz'}] };
result.packages.where(function() {
var name = this.name;
Array.prototype.where = Array.prototype.where || function(predicate) {
var results = [],
len = this.length,
i = 0;
for(; i < len; i++) {
var item = this[i];
if (predicate(item)) {
results.push(item);
}
@nekman
nekman / script.includer.js
Last active October 6, 2015 14:08
Include latest version of jQuery on a website.
(function(d, url) {
var h = d.getElementsByTagName('head')[0],
s = d.createElement('script');
s.src = url;
s.onload = function() {
console.log('loaded %s', url);
};
h.appendChild(s);