Skip to content

Instantly share code, notes, and snippets.

Matthias Käppler mttkay

Block or report user

Report or block mttkay

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mttkay
mttkay / gist:974084
Created May 16, 2011
Ruby OAuth file uploads
View gist:974084
# patch OAuth class to be able to create multipart requests (required for image uploading)
# NOTE that for my purpose I simply made it "auto-sensing" that an image is passed and
# only then creates a multipart body. You may simply want to use some flag instead or whatever.
module OAuth
class Consumer
alias_method :create_default_http_request, :create_http_request
protected
def create_http_request(http_method, path, *arguments)
# CHANGE THIS -- I only did this because it was for a quick-and-dirty script that had to upload pictures
@mttkay
mttkay / gist:1042424
Created Jun 23, 2011
Android photo uploader
View gist:1042424
@Override
protected void onHandleIntent(Intent intent) {
this.nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int jobId = intent.getIntExtra(JOB_ID_EXTRA, -1);
QypeModel model = intent.getParcelableExtra(MODEL_EXTRA);
if (model instanceof Place) {
this.uploadStrategy = new PlacePhotoUploadStrategy((Place) model);
} else if (model instanceof User) {
this.uploadStrategy = new UserPhotoUploadStrategy((User) model);
} else {
@mttkay
mttkay / gist:1105281
Created Jul 25, 2011
Workaround for Android issue 9656
View gist:1105281
public class MyLibrary {
public static final String XMLNS = "http://mylib.com/schema"
}
// in widget class
public class MyWidget {
public MyWidget(Context context, AttributeSet attrs) {
// don't use obtainStyledAttributes, but getAttributeResourceValue:
int myAttr = attrs.getAttributeResourceValue(MyLibrary.XMLNS, "myAttr", -1);
@mttkay
mttkay / gist:1393552
Created Nov 25, 2011
IgnitedAsyncTask sample
View gist:1393552
import com.github.ignition.core.tasks.IgnitedAsyncTask;
public class IgnitedAsyncTaskActivity extends Activity {
private SampleTask task;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
@mttkay
mttkay / gist:1868888
Created Feb 20, 2012
Android social stream view item Activity
View gist:1868888
<activity android:name=".social.ViewStreamItemActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<data android:host="com.android.contacts" android:scheme="content" android:pathPattern="/stream_items/*"/>
</intent-filter>
</activity>
@mttkay
mttkay / gist:1868951
Created Feb 20, 2012
Inserting a StreamItemPhoto
View gist:1868951
private void addStreamItemPhoto(String photoUrl, long streamItemId, String accountName) {
byte[] photoData = downloadPhoto(photoUrl);
ContentValues values = new ContentValues();
values.put(StreamItems.ACCOUNT_NAME, accountName);
values.put(StreamItems.ACCOUNT_TYPE, "com.yourapp.account");
values.put(StreamItemPhotos.STREAM_ITEM_ID, streamItemId);
values.put(StreamItemPhotos.PHOTO, photoData);
resolver.insert(StreamItems.CONTENT_PHOTO_URI, values);
}
View Ruby inheritance
class Base
def m
puts "Base::m"
end
end
module MixinA
def m
puts "MixinA::m"
end
@mttkay
mttkay / gist:2994973
Created Jun 26, 2012
Android declare-styleable sample
View gist:2994973
<resources>
<declare-styleable name="MyWidget">
<attr name="bool_attr" format="boolean" />
<attr name="int_attr" format="integer" />
</declare-styleable>
</resources>
@mttkay
mttkay / gist:2994987
Created Jun 26, 2012
Android use custom attribute
View gist:2994987
<com.example.MyWidget
android:layout_width="wrap_content"
android:layout_height="wrap_content"
bool_attr="true"
int_attr="1" />
@mttkay
mttkay / gist:2995057
Created Jun 26, 2012
Android obtainStyledAttributes
View gist:2995057
public MyWidget(Context context, AttributeSet attrs, int defStyle) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MyWidget, defStyle);
// read attribute values
boolean userBoolAttr = a.getBoolean(R.styleable.bool_attr, false);
int userIntAttr = a.getInteger(R.styleable.int_attr, 0);
// do something with these values
// ...
}
You can’t perform that action at this time.