Skip to content

Instantly share code, notes, and snippets.

View benvium's full-sized avatar

Ben Clayton benvium

  • www.calvium.com
  • Bristol, UK
View GitHub Profile
@benvium
benvium / 0_reuse_code.js
Created August 21, 2014 11:01
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@benvium
benvium / RRDrawable.java
Created August 29, 2014 19:25
Programatically create a drawable with rounded corners
public class RRDrawable extends Drawable {
private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
public RRDrawable(int color) {
paint.setColor(color);
paint.setStyle(Paint.Style.FILL);
}
@Override
public void draw(Canvas canvas) {
@benvium
benvium / [swift]enum-range-printable.swift
Last active August 29, 2015 14:05
Apple Swift: String enums, switch ranges, Printable protocol (description property)
// Playground - noun: a place where people can play
import UIKit
enum State : String {
case ASLEEP = "asleep",
AWAKE = "awake",
DRUNK = "drunk"
}
@benvium
benvium / MyCellSubclass.swift
Created August 30, 2014 19:11
Minimal Swift TableViewController with very basic datasource from a literal array
class MyCellSubclass: UITableViewCell {
@IBOutlet var myNameLabel: UILabel!;
@IBOutlet var myOtherLabel: UILabel!;
// Do not include any inits, or we need to implement
// the required init outself
// http://stackoverflow.com/questions/25126295/swift-class-does-not-implement-its-superclasss-required-members
}
@benvium
benvium / build.txt
Last active August 29, 2015 14:05
add signing using keystore file to an android build.gradle file
android {
compileSdkVersion ...
.....
// Note this section MUST appear before 'buildTypes' in the build.gradle file.
signingConfigs {
release {
storeFile file("filename.keystore")
storePassword "password"
@benvium
benvium / command.sh
Created September 30, 2014 15:49
bash command line parameters and usage help
#!/bin/sh
if [ $# -ne 2 ]; then
echo "Usage: $0 (first parameter) (second parameter) e.g. $0 foo bar";
exit 1;
fi
foo=$1
bar=$2
#import <UIKit/UIKit.h>
@interface UIImage (AddtionalFunctionalities)
//TintColor...
- (UIImage *)imageWithTint:(UIColor *)tintColor;
//scale and resize...
-(UIImage*)scaleToSize:(CGSize)size;
@end
@benvium
benvium / git-code-file-changes.sh
Created October 16, 2014 08:58
Git command to list number of changes to .h and .m files in the last month by a particular user Extension of http://stackoverflow.com/questions/2528111/how-can-i-calculate-the-number-of-lines-changed-between-two-commits-in-git
git log --numstat --author="Ben Clayton" --since "1 month" -- *.m *.h | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d, -%d\n", plus, minus)}'
@benvium
benvium / CustomLogFormatter.h
Last active August 29, 2015 14:12
CocoaLumberjack Custom Log Formatter with time, log level, filename, line number, selector and message. The code `DDLogDebug(@"Enabled notification for status characteristic");` will write to the console: `12:19:13:539 V: DeviceConnector.m:101 bt_onConnected: | Enabled notification for status characteristic`
//
// Created by Ben Clayton on 23/12/14.
// Copyright (c) 2014 Calvium Ltd. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "DDLog.h"
@interface CustomLogFormatter : NSObject<DDLogFormatter>
@benvium
benvium / NSPointerArray+CALCompact.h
Created February 10, 2015 17:25
NSPointerArray compact method that actually works.
#import <Foundation/Foundation.h>
@interface NSPointerArray (CALCompact)
- (void)cal_compact;
@end