Skip to content

Instantly share code, notes, and snippets.

View polarity's full-sized avatar
🌍
Working from home

Robert Agthe polarity

🌍
Working from home
View GitHub Profile
@polarity
polarity / gist:3175479
Created July 25, 2012 10:37
PHP JS Demo
var engine = new PHP ('<?php echo "Hello world!"; ?>');
console.log( engine.vm.OUTPUT_BUFFER); // the outputted buffer from the script!
@polarity
polarity / gist:3513598
Created August 29, 2012 14:42
NSNotificationCenter: Observer hinzufügen
// Typische UIViewController Methode
- (void)viewDidLoad
{
[super viewDidLoad];
// Das aktuelle default NotificationCenter holen und in Variable "nc" referenzieren
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
// Mit nc können wir jetzt....
[nc
@polarity
polarity / gist:3513744
Created August 29, 2012 14:50
NSNotificationCenter: postNotificationName
// Irgendeine Methode in irgendeiner Klasse
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// Das aktuelle default NotificationCenter holen und in Variable "nc" referenzieren
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
// Mit nc können wir jetzt....
[nc
postNotificationName:@"goToProfile" // Alle Abonnenten (subscriber) von "goToProfile" informieren...
object:self // und uns selbst bzw. die Instanz dieser Klasse (self) als Objekt übergeben
@polarity
polarity / gist:3513788
Created August 29, 2012 14:53
NSNotificationCenter: @selector
// toProfileView wird vom NotificationCenter benachrichtigt und ausgeführt
-(void)toProfileView: (NSNotification *)notification
{
// do Stuff...
UIView *object = [NSNotification object];
}
@polarity
polarity / gist:3528446
Created August 30, 2012 13:23
UITextField: Observe text input
// Typische UIViewController Methode
// Wird ausgeführt wenn der View im Speicher
// vollständig geladen wurde.
- (void)viewDidLoad
{
[super viewDidLoad];
// Wir sagen dem handle das er das mit dem Großbuchstaben bei
// neuen Wörtern einfach schon mal lassen soll.
self.handle.autocapitalizationType = UITextAutocapitalizationTypeNone;
@polarity
polarity / gist:3528482
Created August 30, 2012 13:26
UITextField: toLowerCase
// Wird bei jeder Notification (jeder Tastenanschlag)
-(void)type
{
// Text in Kleinbuchstaben umwandeln und wieder in den View schreiben
self.handle.text = [self.handle.text lowercaseString];
}
@polarity
polarity / gist:4375021
Last active December 10, 2015 03:28
How to read and write a cookie
// page one: set cookie after successful login
setCookie("myLogin", "Username or a different String", 2);
// page two: get cookie with this variable name
var cookie = readCookie("myLogin");
// redirect if theres no cookie with this variable
if (!cookie) {
// redirect to page one
@polarity
polarity / index.js
Created February 17, 2013 18:41
voxel.js game
var createGame = require('voxel-engine')
function sphereWorld(x, y, z) {
// return the index of the material you want to show up
// 0 is air
if (x*x + y*y + z*z > 15*15) return 0
return 3
}
var game = createGame({
@polarity
polarity / detect.js
Created April 16, 2013 16:02
"Here are a few browser and operating system detection one liners that have served me well over the years." via http://nextmarvel.net/blog/2011/02/one-line-javascript-browser-detection/
//Browsers
var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/
var IE7 = (document.all && !window.opera && window.XMLHttpRequest && navigator.userAgent.toString().toLowerCase().indexOf('trident/4.0') == -1) ? true : false;
var IE8 = (navigator.userAgent.toString().toLowerCase().indexOf('trident/4.0') != -1);
var IE9 = navigator.userAgent.toString().toLowerCase().indexOf("trident/5")>-1;
var IE10 = navigator.userAgent.toString().toLowerCase().indexOf("trident/6")>-1;
var SAFARI = (navigator.userAgent.toString().toLowerCase().indexOf("safari") != -1) && (navigator.userAgent.toString().toLowerCase().indexOf("chrome") == -1);
var FIREFOX = (navigator.userAgent.toString().toLowerCase().indexOf("firefox") != -1);
var CHROME = (navigator.userAgent.toString().toLowerCase().indexOf("chrome") != -1);
var MOBILE_SAFARI = ((navigator.userAgent.toString().toLowerCase().indexOf("iphone")!=-1) || (navigator.userAgent.toString().toLowerCase().indexOf("ipod")!=-1) || (navigator.userAgent.toString().toLowerCase().indexOf("
@polarity
polarity / .inputrc
Created April 18, 2013 13:52
This allows you to search through your history using the up and down arrows … i.e. type "cd /" and press the up arrow and you'll search through everything in your history that starts with "cd /". Create ~/.inputrc and fill it with this:
"\e[A": history-search-backward
"\e[B": history-search-forward
set show-all-if-ambiguous on
set completion-ignore-case on