Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@adamawolf
adamawolf / Apple_mobile_device_types.txt
Last active April 23, 2024 02:53
List of Apple's mobile device codes types a.k.a. machine ids (e.g. `iPhone1,1`, `Watch1,1`, etc.) and their matching product names
i386 : iPhone Simulator
x86_64 : iPhone Simulator
arm64 : iPhone Simulator
iPhone1,1 : iPhone
iPhone1,2 : iPhone 3G
iPhone2,1 : iPhone 3GS
iPhone3,1 : iPhone 4
iPhone3,2 : iPhone 4 GSM Rev A
iPhone3,3 : iPhone 4 CDMA
iPhone4,1 : iPhone 4S
@staltz
staltz / introrx.md
Last active April 20, 2024 14:15
The introduction to Reactive Programming you've been missing
@JakeWharton
JakeWharton / dex.sh
Last active March 25, 2024 13:54
`classes.dex` method count helpers. Requires smali/baksmali from https://code.google.com/p/smali/ and dexdump from the build-tools in the Android SDK be on your PATH.
function dex-method-count() {
cat $1 | head -c 92 | tail -c 4 | hexdump -e '1/4 "%d\n"'
}
function dex-method-count-by-package() {
dir=$(mktemp -d -t dex)
baksmali $1 -o $dir
for pkg in `find $dir/* -type d`; do
smali $pkg -o $pkg/classes.dex
count=$(dex-method-count $pkg/classes.dex)
name=$(echo ${pkg:(${#dir} + 1)} | tr '/' '.')
@dhh
dhh / gist:1014971
Created June 8, 2011 18:09
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end
@JakeWharton
JakeWharton / ShampooRule.java
Last active August 31, 2023 15:47
Got flaky tests? Shampoo them away with a quick JUnit rule. Apache 2.
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
/** Got flaky tests? Shampoo them away. */
public final class ShampooRule implements TestRule {
private final int iterations;
public ShampooRule(int iterations) {
if (iterations < 1) throw new IllegalArgumentException("iterations < 1: " + iterations);
@chrisbanes
chrisbanes / CollapsingTitleLayout.java
Last active March 26, 2023 11:58
CollapsingTitleLayout
/*
* Copyright 2014 Chris Banes
*
* 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
@seyhunak
seyhunak / devise_helper.rb
Created September 16, 2013 10:50
Devise Error Messages Twitter Bootstrap style
# /app/helpers/devise_helper.rb
module DeviseHelper
def devise_error_messages!
return '' if resource.errors.empty?
messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
sentence = I18n.t('errors.messages.not_saved',
count: resource.errors.count,
resource: resource.class.model_name.human.downcase)
@ryanb
ryanb / shrine_storage.rb
Created January 31, 2018 20:25
Swap between file system and in-memory storage for Shrine file uploads with RSpec.
# This sets up both a memory store and file system store for Shrine file uploads.
# We use the memory store by default but in cases where you want to test actual
# file uploads you can enable it with `file_upload: true` on a per example basis
require "shrine/storage/memory"
require "shrine/storage/file_system"
# We use a delegator to swap out the storage dynamically
# since the storage hash is duplicated for each uploader
class Shrine::Storage::Dynamic < SimpleDelegator
def initialize(initial, storages)