Skip to content

Instantly share code, notes, and snippets.

View cesarferreira's full-sized avatar

César Ferreira cesarferreira

View GitHub Profile
@cesarferreira
cesarferreira / MyRecyclerViewAdapter.kt
Last active July 1, 2021 04:24
DiffUtils kotlin extension
class DeliveryWindowsAdapter : RecyclerView.Adapter<DeliveryWindowsAdapter.ViewHolder>() {
var items: List<DeliveryWindowUiModel> by Delegates.observable(emptyList()) { _, oldList, newList ->
autoNotify(oldList, newList) { o, n -> o.id == n.id }
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val deliveryWindow = items[position]
holder.title.text = deliveryWindow.title
holder.price.text = deliveryWindow.friendlyPrice
@cesarferreira
cesarferreira / base64-to-png.js
Created July 20, 2018 23:42 — forked from miguelmota/base64-to-png.js
Base64 to PNG in Node.js
var fs = require('fs');
var path = require('path');
function base64ToPNG(data) {
data = data.replace(/^data:image\/png;base64,/, '');
fs.writeFile(path.resolve(__dirname, '../tmp/image.png'), data, 'base64', function(err) {
if (err) throw err;
});
}
public abstract class BaseMapperToPresentation<SOURCE, TARGET> {
/**
* Transforms a type into another
*
* @param toBeTransformed source that will be transformed
* @return the transformed object
*/
public abstract TARGET mapToPresentation(SOURCE toBeTransformed);
public abstract class BaseMapperToDomain<SOURCE, TARGET> {
/**
* Transforms a type into another
*
* @param toBeTransformed source that will be transformed
* @return the transformed object
*/
public abstract TARGET mapToDomain(SOURCE toBeTransformed);
@cesarferreira
cesarferreira / HybridMutableLiveData.kt
Created April 30, 2018 21:45
HybridMutableLiveData
class HybridMutableLiveData<T> : MutableLiveData<T>() {
private val pending = AtomicBoolean(false)
private val sticky = AtomicBoolean(false)
@MainThread
override fun observe(owner: LifecycleOwner, observer: Observer<T>) {
// Observe the internal MutableLiveData
super.observe(owner, Observer { t ->
@cesarferreira
cesarferreira / gist:4ff01dcd68a2489f99344b88bee2a85a
Last active March 29, 2018 18:35 — forked from n00neimp0rtant/gist:9515611
simple squash without rebase

within current branch, squashes all commits that are ahead of master down into one

useful if you merged with upstream in the middle of your commits (rebase could get very ugly if this is the case)

commit any working changes on branch "mybranchname", then...

git checkout master
git checkout -b mybranchname_temp
git merge --squash mybranchname
git commit -am "Message describing all squashed commits"
git branch -m mybranchname mybranchname_unsquashed
@cesarferreira
cesarferreira / android_color_transparency.txt
Created February 28, 2018 17:16
android color transparency cheat sheet
<color name="black">#**000000</color>
100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
@cesarferreira
cesarferreira / better-nodejs-require-paths.md
Created September 25, 2017 22:38 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@cesarferreira
cesarferreira / tmux.md
Created September 20, 2017 14:06 — forked from andreyvit/tmux.md
tmux cheatsheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a

@cesarferreira
cesarferreira / zsh.md
Created June 14, 2017 10:00 — forked from tsabat/zsh.md
Getting oh-my-zsh to work in Ubuntu