Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben Clayton benvium

  • www.calvium.com
  • Bristol, UK
View GitHub Profile
@benvium
benvium / 0_reuse_code.js
Created Aug 21, 2014
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// 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 Aug 29, 2014
Programatically create a drawable with rounded corners
View RRDrawable.java
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 / MyCellSubclass.swift
Created Aug 30, 2014
Minimal Swift TableViewController with very basic datasource from a literal array
View MyCellSubclass.swift
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 / [swift]enum-range-printable.swift
Last active Aug 29, 2015
Apple Swift: String enums, switch ranges, Printable protocol (description property)
View [swift]enum-range-printable.swift
// Playground - noun: a place where people can play
import UIKit
enum State : String {
case ASLEEP = "asleep",
AWAKE = "awake",
DRUNK = "drunk"
}
@benvium
benvium / build.txt
Last active Aug 29, 2015
add signing using keystore file to an android build.gradle file
View build.txt
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 Sep 30, 2014
bash command line parameters and usage help
View command.sh
#!/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
View UIImage+AddtionalFunctionalities.h
#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 Oct 16, 2014
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
View git-code-file-changes.sh
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 Aug 29, 2015
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`
View CustomLogFormatter.h
//
// 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 Feb 10, 2015
NSPointerArray compact method that actually works.
View NSPointerArray+CALCompact.h
#import <Foundation/Foundation.h>
@interface NSPointerArray (CALCompact)
- (void)cal_compact;
@end