Skip to content

Instantly share code, notes, and snippets.

View donnfelker's full-sized avatar

Donn Felker donnfelker

View GitHub Profile
@donnfelker
donnfelker / CustomBindingAdapters.kt
Last active October 20, 2017 11:12
MVVM - Removing Logic from Your Views with BindingAdapters
@BindingAdapter(“isVisible”)
fun setIsVisible(view: View, isVisible: Boolean) {
if (isVislble) {
view.visibility = View.VISIBLE
} else {
view.visibility = View.GONE
}
}
@donnfelker
donnfelker / encoding-video.md
Created July 13, 2017 17:35 — forked from Vestride/encoding-video.md
Encoding video for the web

Encoding Video

Installing

Install FFmpeg with homebrew. You'll need to install it with a couple flags for webm and the AAC audio codec.

brew install ffmpeg --with-libvpx --with-libvorbis --with-fdk-aacc --with-opus
@donnfelker
donnfelker / build.gradle
Created January 31, 2014 23:42
Excluding with Gradle
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile('com.google.android.gms:play-services:3.1.+') {
exclude module: 'support-v4'
}
compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:support-v4:13.0.+'
compile 'com.squareup.dagger:dagger:1.1.0'
compile 'com.squareup.dagger:dagger-compiler:1.1.0'
compile 'com.squareup.picasso:picasso:2.1.1'
@donnfelker
donnfelker / friendly_urls.markdown
Created August 26, 2016 20:54 — forked from jcasimir/friendly_urls.markdown
Friendly URLs in Rails

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.

@donnfelker
donnfelker / DeepLinkRouterTest.java
Last active July 19, 2016 10:42
ShadowTaskStackBuilder Blog Code
@Test
public void shouldBeAbleToGoToComments() {
Uri deepLink = Uri.parse("pfm:///user/frank/status/123/?version=88983845");
System.out.println(String.format("Testing %s", deepLink.toString()));
// The intent to start.
Intent expectedIntent = new Intent(Robolectric.application, Status.class);
expectedIntent.putExtra(Constants.Extras.STATUS_ID, 123L);
//r = require('rethinkdb')
var MongoClient = require('mongodb').MongoClient,
format = require('util').format;
var querystring = require('querystring');
var https = require('https');
var Inserter = function (collection) {
this.collection = collection;
@donnfelker
donnfelker / BootstrapModule.java
Last active December 21, 2015 03:38
UrlImageView.java - Abstracts Picasso behind a custom ImageView and injects Picasso via Dagger.
import dagger.Module;
import dagger.Provides;
@Module
(
complete = false
)
public class BootstrapModule {
@Provides
Picasso providesPicasso(Context context) {
@donnfelker
donnfelker / gist:5391243
Created April 15, 2013 20:58
CustomeObject Exampl
public class Customer {
String firstName;
String lastName;
// 20 Other properties
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
@donnfelker
donnfelker / gist:4388456
Created December 27, 2012 13:41
Centering in Bootstrap
http://jsfiddle.net/rfkrocktk/hcQ48/
@donnfelker
donnfelker / example.js
Created June 27, 2012 21:20
Express 3 Changes in res.json
// v0.6.19 way of returning JSON.
exports.index = function(req, res) {
Workout.find({}, function(err, docs) {
if(!err) {
res.json( { workouts: docs }, 200);
} else {
res.json( { message: err }, 500);
}
});
}