Skip to content

Instantly share code, notes, and snippets.

View weverb2's full-sized avatar

Brandon Wever weverb2

View GitHub Profile
@weverb2
weverb2 / ButterKnifeViewHolder.java
Created December 10, 2015 17:10
Adapted from https://gist.github.com/AKiniyalocts/d866274ddb55bfabc4f4 to bind a specific model to a view holder.
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import butterknife.ButterKnife;
/**
* Created by brandon on 12/9/15.
*/
public abstract class ButterKnifeViewHolder<T> extends RecyclerView.ViewHolder {
public ButterKnifeViewHolder(View itemView) {
@weverb2
weverb2 / Barcode.swift
Created October 12, 2016 12:33
Generate Barcode from a string
import UIKit
class Barcode {
class func fromString(string : String, barcodeMode: BarcodeMode) -> UIImage? {
let data = string.dataUsingEncoding(NSASCIIStringEncoding)
let filter = CIFilter(name: barcodeMode.filterName)
filter?.setValue(data, forKey: "inputMessage")
guard let outputImage = filter?.outputImage else {
return UIImage()
@weverb2
weverb2 / tabbar.sh
Created November 14, 2016 22:05
Create iOS Tab Bar icons from images
!#/bin/bash
for var in "$@"
do
filename="${var%.*}"
extension="${var##*.}"
sips --resampleHeightWidth 75 75 "$var" --out tabbar_"$filename"@3x."$extension"
sips --resampleHeightWidth 50 50 "$var" --out tabbar_"$filename"@2x."$extension"
sips --resampleHeightWidth 25 25 "$var" --out tabbar_"$filename"."$extension"
done
import android.graphics.Bitmap
import android.graphics.Color
import com.google.zxing.BarcodeFormat
import com.google.zxing.EncodeHintType
import com.google.zxing.MultiFormatWriter
import com.google.zxing.WriterException
import com.google.zxing.common.BitMatrix
object BarcodeUtil {
@Throws(WriterException::class)
@weverb2
weverb2 / Output.java
Last active January 18, 2017 15:50
Javap ran on a data class
brando:kotlinsample brandon$ javap ServerResponse.class
Compiled from "ServerResponse.kt"
public final class com.brandonwever.android.kotlinsample.ServerResponse {
public final java.lang.String getMessage();
public final void setMessage(java.lang.String);
public final int getStatusCode();
public final void setStatusCode(int);
public final java.lang.String getBody();
public final void setBody(java.lang.String);
public com.brandonwever.android.kotlinsample.ServerResponse(java.lang.String, int, java.lang.String);
@weverb2
weverb2 / Ints.kt
Created April 18, 2017 14:51
Integer Dp to Px extensions
fun Int.pxToDp(): Int = (this / Resources.getSystem().displayMetrics.density).toInt()
fun Int.dpToPx(): Int = (this * Resources.getSystem().displayMetrics.density).toInt()
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
String platform = Theme.of(context).platform.toString();
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: new Center(
child: new Column(
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
@weverb2
weverb2 / basic.kt
Created January 22, 2019 00:34
basic
class MainViewModel : ViewModel()
class MainActivity : AppCompatActivity() {
lateinit var viewModel: MainViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
class MainActivity : AppCompatActivity() {
lateinit var viewModel: MainViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
viewModel = ViewModelProviders.of(this).get(MainViewModel::class.java)