Skip to content

Instantly share code, notes, and snippets.

🤓
🦀

Felipe Lima felipecsl

🤓
🦀
Block or report user

Report or block felipecsl

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@felipecsl
felipecsl / unless.kt
Last active Dec 24, 2017
Kotlin unless like Ruby just for fun
View unless.kt
inline fun <T> unless(stmt: () -> Boolean, block: () -> T, noinline elseBlock: (() -> T)? = null) =
if (!stmt.invoke()) {
block()
} else {
elseBlock?.invoke()
}
// Use like:
unless({ foo == bar }, {
@felipecsl
felipecsl / incrementVersionCode
Created Dec 10, 2013
Increments the android versionCode automatically on each debug or release build
View incrementVersionCode
task('increaseVersionCode') << {
def manifestFile = file("src/main/AndroidManifest.xml")
def pattern = Pattern.compile("versionCode=\"(\\d+)\"")
def matcher = pattern.matcher((CharSequence)manifestFile.getText())
matcher.find()
def versionCode = Integer.parseInt(matcher.group(1))
manifestFile.write(matcher.replaceAll("versionCode=\"" + ++versionCode + "\""))
}
assembleDebug.dependsOn 'increaseVersionCode'
@felipecsl
felipecsl / app.js
Created Sep 9, 2016
Sample use of react-native-maps with a tabbed layout
View app.js
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
TouchableOpacity,
Text,
ViewPagerAndroid,
View,
} from 'react-native';
import MapView from 'react-native-maps';
View keymap.cson
# Your keymap
#
# Atom keymaps work similarly to style sheets. Just as style sheets use
# selectors to apply styles to elements, Atom keymaps use selectors to associate
# keystrokes with events in specific contexts. Unlike style sheets however,
# each selector can only be declared once.
#
# You can create a new keybinding in this file by typing "key" and then hitting
# tab.
#
@felipecsl
felipecsl / gist:c6fa823f20f2087d762a
Created Feb 13, 2015
Fire up Android Intent from ADB (command line)
View gist:c6fa823f20f2087d762a
adb shell am start -a android.intent.action.VIEW -d “scheme://host/path?query=value"
@felipecsl
felipecsl / rxruby.rb
Created Feb 25, 2016
Super simplified and naive (but fun) version of RxRuby I wrote during an endless flight to Brazil
View rxruby.rb
class Observable
def initialize(&on_subscribe)
@on_subscribe = on_subscribe
end
def self.from(arr)
new do |o|
arr.each do |i|
o.on_next(i)
end
@felipecsl
felipecsl / after_commit_with_transactional_fixtures.rb
Created Nov 3, 2011 — forked from outoftime/after_commit_with_transactional_fixtures.rb
Patch ActiveRecord to fire after_commit callbacks at the appropriate time during tests with transactional fixtures.
View after_commit_with_transactional_fixtures.rb
module ActiveRecord
module ConnectionAdapters
module DatabaseStatements
#
# Run the normal transaction method; when it's done, check to see if there
# is exactly one open transaction. If so, that's the transactional
# fixtures transaction; from the model's standpoint, the completed
# transaction is the real deal. Send commit callbacks to models.
#
# If the transaction block raises a Rollback, we need to know, so we don't
View Mongoid connection snippet for MongoHQ + Heroku
Mongoid.configure do |config|
if ENV['RACK_ENV'] == 'development' # ambiente de desenvolvimento
name = "myapp_development"
host = "localhost"
config.master = Mongo::Connection.new.db(name)
config.slaves = [ Mongo::Connection.new(host, 27017, :slave_ok => true).db(name) ]
else # ambiente de produção
uri = URI.parse(ENV['MONGOHQ_URL'])
config.master = Mongo::Connection.from_uri(ENV['MONGOHQ_URL']).db(uri.path.gsub("/", ""))
end
View cristiano_ronaldo.json
{
"page":1,
"totalPages":1,
"totalResults":1,
"type":"FUTPlayerItemList",
"count":1,
"items":[
{
"commonName":"Cristiano Ronaldo",
"firstName":"C. Ronaldo",
View gist:4dadf99531348534d2aa
private static List<File> findAllFiles(String baseDirectory) {
List<File> files = new LinkedList<File>();
List<File> directories = new LinkedList<File>();
directories.add(new File(baseDirectory));
while (!directories.isEmpty()) {
File [] subFiles = directories.remove(0).listFiles();
for (File f : subFiles) {
if (f.isDirectory()) {
You can’t perform that action at this time.