Skip to content

Instantly share code, notes, and snippets.

View md2perpe's full-sized avatar

Per Persson md2perpe

View GitHub Profile
@md2perpe
md2perpe / suggestion.md
Created November 18, 2012 18:55
Suggestion of alternative "implements interface" declaration

Suppose that two interfaces clash:

interface Alpha
{
	function foo();
}

interface Beta
{
	function foo();
@md2perpe
md2perpe / jag-skams-inte.md
Last active April 27, 2021 21:38
Jag skäms inte

Jag skäms inte

Jag skäms inte över att vara svensk.
Men jag skäms över hur vissa ser ned på dem som vill bli svenskar.

Jag skäms inte över den svenska flaggan.
Men jag skäms över hur den används mot dem som vill hissa den.

Jag skäms inte över Sverige.
Men jag skäms över hur vissa anser sig ha ensamrätt till landet.

@md2perpe
md2perpe / gist:3088899
Created July 11, 2012 08:15
HTTP status codes
100 Continue
101 Switching Protocols
102 Processing (WebDAV; RFC 2518)
200 OK
201 Created
202 Accepted
203 Non-Authoritative Information (since HTTP/1.1)
204 No Content
205 Reset Content
206 Partial Content
@md2perpe
md2perpe / Mes-byönner.txt
Last active July 26, 2018 20:06
Mes byönner wa' nest Klumbosbrun (Faut-Per-marschen, Älvdalens brudmarsch)
Mes byönner wa nest Klumbosbrun
og warger iemwid knautum,
og kullur auti budum add ien öx i böjem sen,
då belldum wi wa däler og int stjåv dar ini klautum,
fast brö wa slut å nådår kam bå tråj og fjuäre i renn.
Byönn fick kåjt för öxn å bröde wart fel stjört åv bartjem,
men wi Blibjäskaller warum fel lasog Nuäak auti artjem,
men wi Blibjäskaller warum fel lasog Nuäak auti artjem.
<?php
if(isset($_POST['sendRequest']))
{
//Jag tar emot start-date och end-date via ett formular.
//Jag kor strtotime pa varderna for att omvandla dem till Unix timestamp
$startDate = strtotime($_POST['startDate']);
$endDate = strtotime($_POST['endDate']);
//Uppbyggnad av tabell
echo '<table width="100%" border="1">';
@md2perpe
md2perpe / sd-definitioner.md
Last active August 6, 2018 15:08
Sverigedemokratiska definitioner
  • vänsterextremist, vänsterpack = person(-er) som inte delar SD:s åsikter
  • politiskt korrekt = egenskap hos varje person som inte delar SD:s åsikter; motsatsen är politiskt inkorrekta vilket här blir ett positivt laddat ord.
  • censur = när SD-positiva eller rasistiska inlägg raderas, men inte när SD-negativa eller antirasistiska inlägg raderas
  • tryckfrihet = lag som borde ge dig rätten att smutskasta invandrare, men inte att tala negativt om SD
  • tänka självständigt = dela SD:s åsikter
  • övergrepp av rättssamhället = när en sverigedemokrat döms för brott
  • landsförrädare = en som inte röstar på SD
  • antidemokratisk = alla som inte aktivt underlättar för Sverigedemokraterna.
  • odemokratiskt = när partier valda av 95% av befolkningen styr och inte SD.
  • avskräde = motdemonstrant
@md2perpe
md2perpe / shutdown.php
Created May 9, 2012 15:14
Making a destructor to be run even on fatal error
<?php
class Logger
{
protected $rows = array();
public function __construct()
{
register_shutdown_function(array($this, 'shutdown'));
}
@md2perpe
md2perpe / sec2time.php
Created May 4, 2012 21:21
Convert seconds to years, days, hours, minutes and seconds
function sec2time($time)
{
if(!is_numeric($time))
return false;
$value = array(
'seconds' => 60,
'minutes' => 60,
'hours' => 24,
'days' => 365,
@md2perpe
md2perpe / English
Created March 9, 2012 13:23
Class level dependency injection
I often find a need to let all objects of one class to have access to the same service. It then feels like waste of both time and memory to inject the service into each single object. Instead I'd like to inject the service into the whole class and let in be located on class level.
Example:
You have a web store with order and customer objects.
An order object can - via a customer repository - supply the customer who made the order.
If you fetch a sequence of orders, e.g. to show a list of orders and the customers who made them, every order needs access to the customer repository. At the same time the orders should be filled with information from the database.
I've never seen a discussion about class level DI. Is that never done? If not, how are cases like this handled?
@md2perpe
md2perpe / gist:1886070
Created February 22, 2012 17:04
Binary trees in database with interval halving
For binary trees I've found a variant of nested sets.
The idea is to let
- the root node be represented by the interval [0, 1],
- the two children of the root node be represented by the intervals [0, 1/2] and [1/2, 1] respectively,
- the grandchild nodes by [0, 1/4], [1/4, 1/2], [1/2, 3/4] and [3/4, 1].
Then it's easy to find:
- the left and right children (one or both),
- all descendents of a node,