Skip to content

Instantly share code, notes, and snippets.

View felipecsl's full-sized avatar
⚒️
Building

Felipe Lima felipecsl

⚒️
Building
View GitHub Profile
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
@felipecsl
felipecsl / after_commit_with_transactional_fixtures.rb
Created November 3, 2011 22:13 — 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.
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
@felipecsl
felipecsl / restart coreaudio daemon
Last active October 24, 2024 13:20
Restart Mac OS X coreaudio daemon. Useful if you cannot change the audio output device to Airplay.
sudo kill `ps -ax | grep 'coreaudiod' | grep 'sbin' |awk '{print $1}'`
# or...
sudo killall coreaudiod
@felipecsl
felipecsl / GifDecoder.java
Last active November 1, 2019 02:53
Android custom ImageView that handles animated GIFs.
/**
* Copyright (c) 2013 Xcellent Creations, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
@felipecsl
felipecsl / incrementVersionCode
Created December 10, 2013 19:20
Increments the android versionCode automatically on each debug or release build
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 / NoOverscrollSwipeRefreshLayout.java
Last active July 8, 2024 09:52
Modified Android SwipeRefreshLayout that does not move down the content view on swipe down (no overscroll)
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
### Keybase proof
I hereby claim:
* I am felipecsl on github.
* I am felipecsl (https://keybase.io/felipecsl) on keybase.
* I have a public key whose fingerprint is 4D6F 916F A81F 5861 1066 5FE5 E062 1CF8 F64A 2D1B
To claim this, I am signing this object:
@felipecsl
felipecsl / gist:c6fa823f20f2087d762a
Created February 13, 2015 06:48
Fire up Android Intent from ADB (command line)
adb shell am start -a android.intent.action.VIEW -d “scheme://host/path?query=value"
@felipecsl
felipecsl / gist:74da359d3db68031b638
Created February 13, 2015 06:49
Select long running queries from MySQL. Tweak the time to your desire
SELECT * FROM information_schema.processlist WHERE info IS NOT NULL AND TIME > 1;
@felipecsl
felipecsl / BundleBuilder.java
Last active August 29, 2015 14:17
Convenience classes for Fragment instantiation/setting arguments and chaining Bundle calls. MIT license
import android.os.Bundle;
import android.os.Parcelable;
/**
* A Bundle that doesn't suck. Allows you to chain method calls as you'd expect.
*/
public class BundleBuilder {
private final Bundle bundle;