Skip to content

Instantly share code, notes, and snippets.

View TorbenKoehn's full-sized avatar

Torben Köhn TorbenKoehn

View GitHub Profile
@TorbenKoehn
TorbenKoehn / gist:5636266
Created May 23, 2013 13:58
x-jquery HTML Custom Element Test
<!-- This will produce a CORS error (expected) -->
<!--<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>-->
<element name="x-jquery">
<!-- This will produce a CORS error (expected) -->
<!--<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>-->
<template>
<!-- This won't load at all, even with content in the element -->
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
@TorbenKoehn
TorbenKoehn / array_column.php
Created June 26, 2013 09:40
Polyfill for the PHP 5.4 array_column() function (untested)
<?php
//Signature: array array_column ( array $input , mixed $column_key [, mixed $index_key ] )
if( !function_exists( 'array_column' ) ):
function array_column( array $input, $column_key, $index_key = null ) {
$result = array();
foreach( $input as $k => $v )
$result[ $index_key ? $v[ $index_key ] : $k ] = $v[ $column_key ];
@TorbenKoehn
TorbenKoehn / Path.php
Last active May 15, 2018 12:49
Path manipulation class for PHP frameworks (not fully tested)
<?php
namespace Dwarf;
class Path extends Object implements \IteratorAggregate, \Countable {
protected $path;
public function __construct( $path ) {
@TorbenKoehn
TorbenKoehn / Autoboxing.php
Last active December 19, 2015 02:49
PHP Autoboxing: What it could look like I don't think, multiple autoboxing-functions make sense, a __autobox would indeed be more useful than spl_autobox_register, since you can't "merge" multiple classes defined on autoboxes and frameworks require specific functions. The best way would be enabling/disabling the autoboxing in frameworks, set it …
<?php
class Type {
protected $value;
public function __construct( $value ) { $this->value = $value; }
abstract public function __cast( /* (string) Class name */ $type );
}
<?php
/*
* Die Daten in $_GET befinden sich in der URL
* http://meine-domain.com/api.php?action=test&nocheins=test2
* Hier ist
* $_GET[ 'action' ] === 'test'
* $_GET[ 'nocheins' ] === 'test2'
*
* Die Daten vom POST request befinden sich im Request Body
{{ACTION}} = Die Aktion, die die PHP API empfangen soll
{{METHOD}} = Die HTTP Request Method (Meist GET für lesen, POST für schreiben)
{{GET_DATEN}} = Die GET Daten im Query String Format
{{POST_DATEN}} = Die POST Daten im Query String Format
//prepar request
NSString *urlString = [NSString stringWithFormat:@"http://deineurl.com/api.php?action={{ACTION}}&{{GET_DATEN}}"];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
@TorbenKoehn
TorbenKoehn / OwnScript.md
Created July 17, 2013 09:39
OwnScript Specification

OwnScript Specification

Introduction

What is OwnScript? ...you might ask. OwnScript is a programming language based on good parts of specific other languages, namely PHP, JavaScript, Java, Ruby and C#

@TorbenKoehn
TorbenKoehn / express-bind.js
Last active December 19, 2015 23:08
A simple module system for express (Node.js)
app.bind = function( entryPoint, middleware, module ) {
if( !module ) {
module = middleware;
middleware = null;
}
var methods = { get: 'get', post: 'post', put: 'put', delete: 'del' };
for( var i in module ) {
@TorbenKoehn
TorbenKoehn / captcha.php
Created November 14, 2013 12:12
A really old captcha system I found somewhere in my old codes.
<?php
//Simple Captcha Function
//Creates funny and not that easily readable captchas
// ================
// (c) 2009 by DarkDevine
// Modificate as you want, just keep some credits
// Fonts from http://urbanfonts.com , you can get new ones there as well
// ================
// Usage: generate_captcha( $mode ) for generating the captcha,
// check_captcha( $string) for checking with user input
namespace OwnScript.MyNamespace
use OwnScript.SomeOtherNamespace //kein * nötig, da OwnScript keine Klasse, sondern ein Namespace ist
use Vendor.Some.Other.Stuff
class MyClass > DerivedClass:
public myProperty:
get: