Skip to content

Instantly share code, notes, and snippets.

View Broich's full-sized avatar

Kersten Broich

View GitHub Profile
server.get('/bla', function(req, res) {
// instead of adding the implementation here
});
// create a new function here
function doBla(req, res) {
// implementation here
});
// now add it to exports
@Broich
Broich / DebugUserDefaultsViewController.swift
Last active June 29, 2016 15:57
Display NSUserDefaults in a UITableViewController (Swift)
class DebugUserDefaultsViewController: UITableViewController {
var userDefaults = NSUserDefaults.standardUserDefaults().dictionaryRepresentation() as NSDictionary
override func viewDidLoad() {
super.viewDidLoad()
title = "NSUserDefaults"
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
MyViewController: UIViewController {
let refreshControl: UIRefreshControl = {
$0.tintColor = Theme.currentTheme().textColor
$0.addTarget(self, action: #selector(refresh(_:)), forControlEvents: .ValueChanged)
return $0
}(UIRefreshControl())
override func viewDidLoad() {
@Broich
Broich / gist:b91e24afece84ee491a1
Created March 23, 2016 11:23
Filter Localization.strings
"CATEGORY_MEAL_CUISINE" = "Cuisine";
"CATEGORY_MEAL_CUISINE_CHINESE" = "Chinese";
"CATEGORY_MEAL_CUISINE_ITALIAN" = "Italian";
"CATEGORY_MEAL_CUISINE_INDIAN" = "Indian";
"CATEGORY_MEAL_CUISINE_SPANISH_PORTUGUESE" = "Spanish and Portuguese";
"CATEGORY_MEAL_CUISINE_AMERICAN" = "American";
"CATEGORY_MEAL_CUISINE_MIDDLE_EASTERN" = "Middle Eastern";
"CATEGORY_MEAL_CUISINE_ASIAN" = "Asian";
"CATEGORY_MEAL_CUISINE_EUROPEAN" = "European";
- (void)uploadImageToServer
{
[SVProgressHUD showWithStatus:@"Hochladen" maskType:SVProgressHUDMaskTypeBlack];
NSData *imageToUpload = UIImageJPEGRepresentation(self.croppedImage, 90);
if (!imageToUpload) {
NSLog(@"no data available");
return;
} else {
@Broich
Broich / gist:11041839
Last active August 29, 2015 14:00
I wonder if the operation addObjectsFromArray happens in constant time
- (void)createWallOfFame:(NSArray *)newWallOfFameMembers
{
NSLog(@"add %i new member(s) into wall of fame", (int)newWallOfFameMembers.count);
NSMutableArray *currentMembers = [NSMutableArray arrayWithArray:self.members];
if (currentMembers.count > 0) { // only if members are available there is a reason to delete them an the end
NSRange rangeForMembersToDelete = NSMakeRange(currentMembers.count-newWallOfFameMembers.count, newWallOfFameMembers.count);
NSLog(@"delete members from position: %d with length: %d", (int)rangeForMembersToDelete.location, (int)rangeForMembersToDelete.length);
[currentMembers removeObjectsInRange:rangeForMembersToDelete];
}
#import "NSObject+Log.h"
#import <objc/runtime.h>
@implementation NSObject (Log)
- (void)log:(id)logObject
{
unsigned int numberOfProperties = 0;
objc_property_t *propertyArray = class_copyPropertyList([logObject class], &numberOfProperties);
NSLog(@"Property List for: %@", NSStringFromClass([self class]));
<?php
$uploaddir = 'images/';
$file = basename($_FILES['file']['name']);
$uploadfile = $uploaddir . $file;
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
echo "OK";
} else {
echo "ERROR";
}
- (void)layoutSubviews
{
[super layoutSubviews];
if (self.viewOption == BKCollectionViewOptionGalery) {
NSLog(@"layout for galery");
self.userImageView.frame = CGRectMake(5.0f, 5.0f, 143.0f, 143.0f);
self.nameLabel.frame = CGRectMake(5.0f, 153.0f, 143.0f, 20.0f);
self.separationLine.frame = CGRectMake(5.0f, 174.0f, 143.0f, .5f);
self.onlineStatusImageView.frame = CGRectMake(5.0f, 175.0f, 20.0f, 15.0f);
UIView *userNameHackView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 15.0f, 20.0f)];
self.usernameTextField.leftView = userNameHackView;
self.usernameTextField.leftViewMode = UITextFieldViewModeAlways;