Skip to content

Instantly share code, notes, and snippets.

View SleeplessByte's full-sized avatar
💎
💎 💎 💎

Derk-Jan Karrenbeld SleeplessByte

💎
💎 💎 💎
View GitHub Profile
@SleeplessByte
SleeplessByte / resolve.java
Created May 7, 2015 14:42
Resolve a resource ID for Android
/**
* Resolve id
*
* @param context the context
* @param id the id
* @return the resolved id
*/
public static String resolveId( Context context, int id ) {
StringBuilder out = new StringBuilder();
out.append(" #");
@SleeplessByte
SleeplessByte / FlagUtils.java
Created May 7, 2015 22:17
Flag utilities for parcelable or packing/unpacking in general
public class FlagUtils {
/**
* Packs booleans into an integer
*
* This does not check if the number of booleans is less then the number of bits in the integer
*
* @param params the booleans
*
* @return the packed integer
@SleeplessByte
SleeplessByte / music.md
Last active August 29, 2015 14:20
Music during Daily Droid feat. Rx and AppCompat
@SleeplessByte
SleeplessByte / build.gradle
Created May 8, 2015 00:05
singning.properties configuration in your build.gradle so your credentials are safe(r)
File propFile = file('signing.properties');
if (propFile.exists()) {
def Properties props = new Properties()
props.load(new FileInputStream(propFile))
if (props.containsKey('STORE_FILE') &&
props.containsKey('STORE_PASSWORD') &&
props.containsKey('KEY_ALIAS') &&
props.containsKey('KEY_PASSWORD')) {
@SleeplessByte
SleeplessByte / xml_entity.rb
Created July 27, 2015 13:20
Camelize Grape Entity output
class XmlEntity < Grape::Entity
protected
def self.key_for( attribute )
( exposures[ attribute.to_sym ][ :as ] || name_for( attribute ) ).to_s.camelize
end
end
@SleeplessByte
SleeplessByte / my_base_entity.rb
Created July 27, 2015 13:21
Access Grape Routes from entity
class MyBaseEntity < Grape::Entity
include GrapeRouteHelpers::NamedRouteMatcher
end
@SleeplessByte
SleeplessByte / api-namespace-api.rb
Created July 27, 2015 13:23
Use same format, prefix, formatter and error handler for multiple grape api's
module Namespace
module API
extend ActiveSupport::Concern
included do
format :xml
prefix :api
formatter :xml, xml_formatter
rescue_from :all do |e|
@SleeplessByte
SleeplessByte / empty_my_model.rb
Created July 27, 2015 13:26
Empty default active record
class EmptyMyModel < Delegator
def initialize
super @_delegated_object = MyModel.new(
#mydefaultparamters,
id: 0
)
end
def __getobj__