Skip to content

Instantly share code, notes, and snippets.

View Stoffo's full-sized avatar

Stefan Lange Stoffo

  • Hamburg, Germany
  • 08:39 (UTC +02:00)
View GitHub Profile
@Stoffo
Stoffo / jsonp_example.php
Last active September 21, 2015 14:28
simple example for an implemention of jsonp in php
<?php
$callback = $_GET['callback'];
$json = json_encode(['foo' => 'bar'], JSON_FORCE_OBJECT);
if ($callback) {
header('Content-Type: text/javascript');
echo $callback.'(';
echo $json;
echo ');';
@Stoffo
Stoffo / has_focus.js
Created March 4, 2015 13:33
Check if the Window has the focus or not
var has_focus;
$(window).focus(function () {
has_focus = true;
document.title = "focus";
}).blur(function () {
has_focus = false;
document.title = "no focus"
});
$.urlParam = function (name) {
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (results === null) {
return null;
}
return results[1] || 0;
};
var PID = $.urlParam("PID"); //123456
@Stoffo
Stoffo / http_statuscodes.php
Last active October 26, 2017 11:24
PHP Array with alle HTTP Status Codes
<?
$http_codes = array(
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing',
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
@Stoffo
Stoffo / CSV_MySQL_import.php
Last active August 29, 2015 14:10
import a CSV file easily with this file
#!/usr/bin/php
<?php
error_reporting(0);
$server = "localhost";
$port = 3306;
$username = "csv_test";
$password = "test";
$db = "test_db";
@Stoffo
Stoffo / JSModulePattern2.js
Created November 6, 2014 09:55
Another example of the module pattern that exposes the module a little differently and makes use of a shared private cache. This method encourages more of an object creation approach where we can optimize performance by being efficient with shared storage.
var MyModule = ( function( window, undefined ) {
// this object is used to store private variables and methods across multiple instantiations
var privates = {};
function MyModule() {
this.myMethod = function myMethod() {
alert( 'my method' );
};
@Stoffo
Stoffo / JSModulePattern1.js
Last active August 29, 2015 14:08
This pattern is used to mimic classes in conventional software engineering and focuses on public and private access to methods & variables. The module pattern strives to improve the reduction of globally scoped variables, thus decreasing the chances of collision with other code throughout an application.
( function( window, undefined ) {
// normally variables & functions start with a lowercase letter but with modules, that is not the case.
// The general tradition is to start them with a capital letter instead.
function MyModule() {
// `this` refers to the instance of `MyModule` when created
this.myMethod = function myMethod() {
alert( 'my method' );
};
@Stoffo
Stoffo / check_mongodb_collection_exists.php
Last active September 21, 2015 14:23
Check MongoDB Collection Existance
<?php
/**
* Checks if a Collection already exists.
* Returns true if Collection exists, otherwise it returns false.
*
* @param $collection
*
* @return bool
*/