Skip to content

Instantly share code, notes, and snippets.

View snichme's full-sized avatar

Magnus Landerblom snichme

  • 84codes
  • Stockholm
View GitHub Profile
@snichme
snichme / gist:771164
Created January 8, 2011 21:22
Simple script for listing the different hash algorithms installed on your system
<pre>
<?php
function microtime_float() {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$algos = hash_algos();
$string = "The quick brown fox jumped over the lazy dog.";
@snichme
snichme / gist:789589
Created January 21, 2011 12:05
A Doctrine logger for FireBug(FirePHP)
<?php
/**
* Doctrine logger for FireBug
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Magnus Andersson <mange@mange.name>
*/
namespace My\Namespace;
use Doctrine\DBAL\Logging\SqlLogger;
@snichme
snichme / gist:1055123
Created June 29, 2011 22:01
Singleton pattern in Javascript
var obj = (function(){
function Class() {
}
Class.prototype = {
_var : null,
func1 : function() {
},
func2 : function() {
}
};
(function(fn, i) {
(function () {
fn(i++) ? arguments.callee() : null;
}());
}(function(fn, max) {
return function(i) {
fn(i);
return i<max;
};
}(console.log, 50), 30));
@snichme
snichme / Head.js example
Created January 31, 2013 13:44
Head.js example
<script>
head.ready(function() {
// Use your javascript here...
// Load a new js file:
head.js("path/to/file.js", function() {
// here the new script is available
});
@snichme
snichme / gist:5266306
Created March 28, 2013 19:57
Is this a good way for producing a json respons of users with their cars?
implicit val carWriter = Json.writes[Car]
implicit val userWithCarWriter = Json.writes[UserWithCar]
def users = Action {
val users = DB.withSession { implicit session =>
val q = for {
u <- Users
c <- Cars if u.carId === c.id
} yield (u, c)
q.list.map { row =>
@snichme
snichme / AMD-jquery-plugin.js
Created April 25, 2013 16:04
Making jQuery plugins AMD compatible
(function (factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery'], factory);
} else {
factory(jQuery);
}
}(function ($) {
$.fn.jqueryPlugin = function () {};
}));
@snichme
snichme / pure.zsh
Created July 9, 2013 21:38
My zsh theme
# Pure
# by Sindre Sorhus
# https://github.com/sindresorhus/pure
# MIT License
# Change this to your own username
DEFAULT_USERNAME='mange'
# Threshold (sec) for showing cmd exec time
@snichme
snichme / grunt-cram.js
Last active December 21, 2015 22:58
Example grunt task for Cram.js
module.exports = function(grunt) {
'use strict';
grunt.registerMultiTask('cram', 'Cram runner for grunt', function() {
// Cram failed, tell grunt
function fail (ex) {
grunt.fail.warn('cram failed: ', ex && ex.message || ex);
if (ex && ex.stack) console.log(ex.stack);
}