Skip to content

Instantly share code, notes, and snippets.

View abombss's full-sized avatar

Adam Tybor abombss

  • Accenture
  • Chicago, IL
View GitHub Profile
package roboguice.astroboy;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import roboguice.inject.InjectView;
import java.util.List;
@abombss
abombss / ContextRunner.java
Created February 5, 2011 07:39
Poor Man's Mspec in Java
public class ContextRunner extends Runner {
static class SpecificationMethod {
Class<?> TestContainerType;
Description TestContainerDescription;
ContextSpecification ContextSpecification;
Description ContextSpecificationDescription;
Field ContextSpecificationField;
Method SpecificationMethod;
Description SpecificationDescription;
}
@abombss
abombss / RobolectricGuicyTestRunner.java
Created February 9, 2011 05:44
Robolectric test runner with modifications for RoboGuice 1.2-SNAPSHOT
public class RobolectricGuicyTestRunner extends RobolectricTestRunner {
public RobolectricGuicyTestRunner(Class testClass) throws InitializationError {
super(testClass, new File("./application").exists() ? new File("./application") : new File("./"));
}
@Override
protected Application createApplication() {
Application app = super.createApplication();
Injector injector = RoboGuice.getInjector(Stage.PRODUCTION, app,new RoboModule(app), new RobolectricModule());
return app;
@abombss
abombss / WakefulIntentService.java
Created February 21, 2011 18:02
A compatible wakeful intent service
/***
Copyright (c) 2009 CommonsWare, LLC
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
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@abombss
abombss / Usage.java
Created February 25, 2011 19:16
A roboguice provider for creating a User-Agent string on android
public class MyModule extends AbstractModule {
@Override
void configure() {
bind(String.class).annotatedWith(UserAgent.class).to(UserAgentProvider.class);
}
}
public class MyComponent {
String userAgent;
@abombss
abombss / gist:937804
Created April 22, 2011 22:13
Fugly mvc
var model = new
{
Accounts = accounts.Select(x => x.ToExpando()),
TotalUsers = totalUsers,
Page = page,
};
return View(model.ToExpando());
@abombss
abombss / CQRS.cs
Created June 4, 2011 05:15 — forked from ToJans/CQRS.cs
Simple concept code to show how CQRS works
//---><8--------------------------- UI loads viewmodels and generates commands ----
UI.Viewmodel = ViewModelStore.Query(UI.SomeParameters);
UI.HandleInput = GeneratedCommand => CommandStore.Add(GeneratedCommand);
//---><8--------------------------- Commands to events -----------------------------------------
// This uses an iterator because a command should only be handled once
while(CommandStore.HasCommands)
@abombss
abombss / jquery-iebuttonfix.js
Created June 15, 2011 07:28
JQuery plugin to fix the html <button> issue when submitting forms in IE <= 7
(function ($) {
/// <param name="$" type="jQuery">JQuery</param>
$.fn.iebuttonfix = function() {
return $(this).each( function() {
var $f = $(this);
if ($f.prop("nodeName").toLowerCase() === "form") {
$f.submit(function() {
$("button", $f).each(function() {
var $b = $(this);
if ($b.data("ie.btnfix.clicked")) {
@abombss
abombss / Extensions.cs
Created June 17, 2011 04:49
C# Safe navigation operator as extension
public static class Extensions
{
public static TResult SafeInvoke<TModel, TResult>(this TModel model, Func<TModel, TResult> expression, TResult nullValue = default(TResult))
{
try
{
return expression(model);
}
catch (NullReferenceException)
{
@abombss
abombss / jquery-cascadingselect.js
Created June 17, 2011 05:40
JQuery plugin for Cascading Selects
(function ($) {
/// <summary>JQuery plugin for handling cascading html select lists</summary>
/// <param name="$" type="jQuery">JQuery</param>
$.fn.cascadingSelect = function() {
this.each(function() {
var $e = $(this);
var $p = $($e.attr("data-ui-cascading-parent"));
$e.data('cascading-opts', $e.find("option:gt(0)"));