Skip to content

Instantly share code, notes, and snippets.

View tunitowen's full-sized avatar

Tony Owen tunitowen

  • OwenTech Ltd
  • Leeds
View GitHub Profile
@tunitowen
tunitowen / adbconnect.sh
Created November 7, 2013 13:02
Shell script to enable ADB over TCPIP
#!/bin/sh
IP_ADDRESS=$(adb shell ifconfig wlan0 | awk '{print $3}')
echo $IP_ADDRESS
adb tcpip 5555
adb connect $IP_ADDRESS
@tunitowen
tunitowen / gist:9599186
Last active June 24, 2017 17:27
HTML to NSAttributedString
NSString *html = @"<div style='font: 18pt Helvetica-Light; color: #3498DB;'>Blue Text<span style='color: #AAAAAA;'>GreyText</span></div>"];
NSData *htmlData = [html dataUsingEncoding:NSUTF8StringEncoding];
NSMutableAttributedString *htmlAttributedString = [[NSMutableAttributedString alloc] initWithData:htmlData options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType} documentAttributes:nil error:nil];
[label setAttributedText:htmlAttributedString];
@tunitowen
tunitowen / gist:9618413
Last active August 29, 2015 13:57
NSNumber Macros
// magic macros
#define N(x) [NSNumber numberWithInt: x]
#define B(x) [NSNumber numberWithBool: x]
NSMutableArray *array = [[NSMutableArray alloc] init];
// long way
[array addObject:[NSNumber numberWithBool:YES]];
[array addObject:[NSNumber numberWithInt:1]];
@tunitowen
tunitowen / designer.html
Last active August 29, 2015 14:07
designer
<link rel="import" href="../core-scaffold/core-scaffold.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<link rel="import" href="../core-menu/core-menu.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-menu/core-submenu.html">
<link rel="import" href="../paper-checkbox/paper-checkbox.html">
<link rel="import" href="../paper-button/paper-button.html">
@tunitowen
tunitowen / build.gradle
Created May 19, 2017 07:54
Room-GettingStarted-Gradle
apply plugin: 'kotlin-kapt'
android {
...
}
dependencies {
...
// Room
compile 'android.arch.persistence.room:runtime:1.0.0-alpha1'
@tunitowen
tunitowen / Person.kt
Created May 19, 2017 07:57
Room-GettingStarted-Entity
@Entity
data class Person(
@PrimaryKey(autoGenerate = true)
val uid: Long,
val firstName: String = "",
val lastName: String = ""
)
@tunitowen
tunitowen / PersonDao.kt
Created May 19, 2017 08:02
Room-GettingStarted-DAO
@Dao
interface PersonDao {
@Query("SELECT * FROM person")
fun getAllPeople(): Flowable<List<Person>>
@Insert
fun insert(person: Person)
}
@tunitowen
tunitowen / MyDatabase.kt
Created May 19, 2017 08:08
Room-GettingStarted-Database
@Database(entities = arrayOf(Person::class), version = 1)
abstract class MyDatabase : RoomDatabase() {
abstract fun personDao(): PersonDao
}
@tunitowen
tunitowen / MyApp.kt
Created May 19, 2017 08:13
Room-GettingStarted-AppSetup
class MyApp : Application() {
companion object {
var database: MyDatabase? = null
}
override fun onCreate() {
super.onCreate()
MyApp.database = Room.databaseBuilder(this, MyDatabase::class.java, "we-need-db").build()
}
@tunitowen
tunitowen / AddPerson.kt
Created May 19, 2017 08:29
Room-GettingStarted-AddData
fun addPerson(firstName: String, lastName: String) {
val person = Person(0, firstName, lastName)
Single.fromCallable {
MyApp.database?.personDao()?.insert(person)
}.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()).subscribe()
}