Skip to content

Instantly share code, notes, and snippets.

View joshdholtz's full-sized avatar
👨‍👩‍👦
Family first then OSS

Josh Holtz joshdholtz

👨‍👩‍👦
Family first then OSS
View GitHub Profile
@joshdholtz
joshdholtz / some_layout.xml
Created June 20, 2012 04:31
Android - flex space between views
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout android:id="@+id/activity_webview_toolbar"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:orientation="horizontal"
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
webview = (WebView)this.findViewById(R.id.activity_webview_webview);
// Enables javascript
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
@joshdholtz
joshdholtz / setup.sql
Created July 12, 2012 17:20
Postgres Database Setup
-- psql -f setup.sql -U username postgres
CREATE USER dbusername WITH PASSWORD 'password';
CREATE DATABASE dbname;
GRANT ALL PRIVILEGES ON DATABASE dbname to dbusername;
@joshdholtz
joshdholtz / BrokenGoogleSample.java
Created August 13, 2012 20:59
Android: In App Billing Sample Fix
/**
* Called when a button is pressed.
*/
@Override
public void onClick(View v) {
if (v == mBuyButton) {
if (Consts.DEBUG) {
Log.d(TAG, "buying: " + mItemName + " sku: " + mSku);
}
@joshdholtz
joshdholtz / Thing.m
Created December 10, 2012 23:30
iOS Date Parse
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSDate *date = nil;
NSError *error = nil;
if (![dateFormatter getObjectValue:&date forString:jsonValue range:nil error:&error]) {
NSLog(@"Date '%@' could not be parsed: %@", self, error);
}
@joshdholtz
joshdholtz / DatesSuck.m
Created December 11, 2012 01:07
StupidDate
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSDate *date = nil;
NSError *error = nil;
if (![dateFormatter getObjectValue:&date forString:self range:nil error:&error]) {
NSLog(@"Date '%@' could not be parsed: %@", self, error);
}
@joshdholtz
joshdholtz / ImGoodAndIKnowIt.m
Created December 11, 2012 01:16
Dates bow down to me
//
// ViewController.m
// Stupid
//
// Created by Josh Holtz on 12/10/12.
// Copyright (c) 2012 RokkinCat. All rights reserved.
//
#import "ViewController.h"
@joshdholtz
joshdholtz / drawable.xml
Created December 11, 2012 19:19
PutThisDrawableOnTheRootOfTheCell
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid
android:color="#449def" />
<stroke
android:width="1dp"
android:color="#2f6699" />
<corners
@joshdholtz
joshdholtz / SomeActivity.java
Created December 13, 2012 22:18
Listening and sending broadcasts
public class HomeActivity extends Activity {
@Override
public void onResume() {
super.onResume();
registerReceiver(myBroadcastReceiver, new IntentFilter("com.package.name.BROADCAST_NAME_GOES_HERE"));
}
@Override
public void onPause() {
@joshdholtz
joshdholtz / SomeActivity.java
Created January 8, 2013 16:24
Using Protocol Android to retrieve Stripe credit card token with an async request
private void getStripeToken(String stripeApi, String cardNumber, String expMonth, String expYear, String cvc) {
// Sets basic auth header with Stripe API key and adds post params for number, exp month, exp year, and cvc
ParamsRequestData requestData = new ParamsRequestData();
requestData.addBearerAuthHeader(stripeApi);
requestData.addParam("card[number]", cardNumber);
requestData.addParam("card[exp_month]", expMonth);
requestData.addParam("card[exp_year]", expYear);
requestData.addParam("card[cvc]", cvc);