Skip to content

Instantly share code, notes, and snippets.

@shawnwall
shawnwall / gist:2215212
Created March 27, 2012 11:41
Unit testing blocks with AFNetworking example
/*
* SenTestingKit does not wait for blocks to finish by default so your test would simply complete
* as successful. You need to use a semaphore and keep the run loop going in order for the test
* to properly run.
*/
- (void)testGetSpots {
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
CLLocation location = [[CLLocation alloc] initWithLatitude:70.0 longitude:50.0];
[Spot spotsWithURLString:@"/spots" near:location parameters:[NSDictionary dictionaryWithObject:@"128" forKey:@"per_page"] block:^(NSArray *records) {
//sample assert
@evanbeard
evanbeard / registrations_controller.rb
Created May 11, 2012 19:53 — forked from jwo/registrations_controller.rb
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@JakeWharton
JakeWharton / BaseActivity.java
Created July 6, 2012 01:17
Scoped event bus which automatically registers and unregisters with the lifecycle.
package com.squareup.example;
public abstract BaseActivity extends SherlockActivity {
private final ScopedBus scopedBus = new ScopedBus();
protected ScopedBus getBus() {
return scopedBus;
}
@Override public void onPause() {
@florianmski
florianmski / convertLocalizable.rb
Created August 23, 2012 22:14
Convert your Localizable.strings (iOS) to strings.xml (Android)
#!/usr/bin/ruby
# based on https://github.com/tmurakam/cashflow/blob/0a01ac9e0350dfb04979986444244f8daf4cb5a8/android/convertStrings.rb
# support comments and Converter such as "%@", "%d", "%0.1f"...
# in your directory : ./main.rb Localizable.strings
file = File.open("strings.xml", "w");
file.puts "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
file.puts "<resources>"
@irace
irace / BIWebViewDelegate.m
Created September 10, 2012 02:51
JavaScript/native bridge for iOS's UIWebView
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
NSString *urlString = [[request URL] absoluteString];
if ([urlString hasPrefix:@"js:"]) {
NSString *jsonString = [[[urlString componentsSeparatedByString:@"js:"] lastObject]
stringByReplacingPercentEscapes];
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
@krzysztofzablocki
krzysztofzablocki / gist:3951446
Created October 25, 2012 08:36
Simple crossfade
[UIView transitionWithView:cell.imageView duration:0.25f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
cell.imageView.image = decompressedThumbnail;
} completion:nil];
@pyricau
pyricau / ThreadPreconditions.java
Created November 29, 2012 09:59
Check that your UI APIs are called from the UI Thread
public class ThreadPreconditions {
public static void checkOnMainThread() {
if (BuildConfig.DEBUG) {
if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
throw new IllegalStateException("This method should be called from the Main Thread");
}
}
}
}
@drmillan
drmillan / gist:a7cf12753fbe5d1920b8
Last active December 12, 2015 01:49
Procedimiento de pruebas

Objeto de la prueba

##Errores generales

  • Los errores que se muestran al usuario ¿Deben ser bloqueantes?

  • Los errores que se muestran al usuario, son claros, respetan las reglas:

    1: Título genérico (p.e. Error al enviar el carrito)

2: Descripción del error (no técnica) (p.e. No se pudo conectar con la tienda)

@JakeWharton
JakeWharton / BindingAdapter.java
Last active July 25, 2023 05:49
An adapter base class that uses a new/bind pattern for its views.
// Apache 2.0 licensed.
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
/** An implementation of {@link BaseAdapter} which uses the new/bind pattern for its views. */
public abstract class BindableAdapter<T> extends BaseAdapter {
@marczych
marczych / MyActivity.java
Last active April 12, 2023 12:54
This is a workaround for `android:showAsAction="withText"` not displaying text on narrow layouts e.g. in portrait on phones. This uses styles found in ActionBarSherlock so it matches the native styling. I tested it with ABS v4.4.0 but earlier versions are probably compatible.Note: This should only be used if you absolutely have to display the te…
public class MyActivity extends Activity {
...
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Trigger onOptionsItemSelected for the custom menu item because it doesn't
// happen automatically.
final MenuItem item = menu.findItem(R.id.button_id);
barcodeItem.getActionView().setOnClickListener(new OnClickListener() {
@Override