Skip to content

Instantly share code, notes, and snippets.

View bearprada's full-sized avatar
🎯
Focusing

PRADA Hsiung bearprada

🎯
Focusing
  • Facebook
  • London, UK
View GitHub Profile
...
protected onCreate(Bundle savedStateInstance) {
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint("https://example.com")
.build();
SampleService service = restAdapter.create(SampleService.class);
List<Repo> repos = service.listRepos("PRADA", 10);
}
...
@bearprada
bearprada / MainActivity.java
Last active August 29, 2015 14:03
Restful API Integration on Android
...
protected onCreate(Bundle savedStateInstance) {
NetworkTask task = new NetworkTask(this);
NetworkTask.execute();
}
public void successful(List<Repo> repos) {
// do something
}
public void fail(Exception e) {
@bearprada
bearprada / alg1.java
Created April 18, 2015 15:54
quiz_match_company_times
for (Company comp : companies) {
int userIdx = 0
for (Time time : comp.times) {
(0..5).each {
time.add(comp.user[userIdx++])
}
}
}
@bearprada
bearprada / gist:1ff7fb05ba04c8a79cf4
Created April 19, 2015 01:11
2015 AWS SFO Summit
Online Video :
https://www.youtube.com/playlist?list=PLhr1KZpdzukeD0iBeDI9WqZLYtuaFaaGc&mkt_tok=3RkMMJWWfF9wsRonu67Jc%2B%2FhmjTEU5z16eUoW66%2Fh4kz2EFye%2BLIHETpodcMT8NgMLDYDBceEJhqyQJxPr3NJdMN0cN8RhjjAQ%3D%3D
Slides
http://www.slideshare.net/AmazonWebServices/tag/2015sfsummit?mkt_tok=3RkMMJWWfF9wsRonu67Jc%2B%2FhmjTEU5z16eUoW66%2Fh4kz2EFye%2BLIHETpodcMT8NgMLDYDBceEJhqyQJxPr3NJdMN0cN8RhjjAQ%3D%3D
@bearprada
bearprada / sample_gson_deserializer
Created June 14, 2015 03:39
the sample code to use JsonDeserializer to handle the nest/complicate JSON format
/**
* Example :
* input : {server: { result : { data: { a:1, b:2 }} }}
**/
public class MyDeserializer implements JsonDeserializer<MyClass> {
public MyClass deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
JsonElement j = json.getAsJsonObject().get("server").getAsJsonObject().get("result").getAsJsonObject().get("data");
MyClass clz = new MyClass();
RxView.clicks(v.findViewById(R.id.btn_detail_new_image)).map(aVoid -> "Event_Click_Detail_New_Image")
.mergeWith(RxView.clicks(v.findViewById(R.id.btn_detail_comment)).map(aVoid -> "Event_Click_Detail_Comment"))
.mergeWith(RxView.clicks(v.findViewById(R.id.btn_detail_map)).map(aVoid -> "Event_Click_Detail_Map"))
.mergeWith(RxView.clicks(v.findViewById(R.id.btn_detail_report)).map(aVoid -> "Event_Click_Detail_Report"))
.mergeWith(RxView.clicks(v.findViewById(R.id.btn_detail_share)).map(aVoid -> "Event_Click_Detail_Share"))
.mergeWith(RxView.clicks(v.findViewById(R.id.btn_detail_like_text)).map(aVoid -> "Event_Click_Detail_Like"))
.mergeWith(RxView.clicks(v.findViewById(R.id.btn_detail_share_text)).map(aVoid -> "Event_Click_Detail_Share"))
.mergeWith(RxView.clicks(v.findViewById(R.id.detail_story)).map(aVoid -> "Event_Click_Detail_Story"))
.subscribe(s -> FlurryAgent.logEvent(s, false));
/**
* Background database for lookups of fittest color to represent.
*/
private static List<Pair<Integer, String>> sBackgrounds = new ArrayList<>();
static {
// Color Tickets: ------------A-R-G-B-
sBackgrounds.add(new Pair<>(0xFF040404, "background_01.png"));
sBackgrounds.add(new Pair<>(0xFF040404, "background_02.png"));
sBackgrounds.add(new Pair<>(0xFFF2F2F2, "background_03.png"));
...
Giffle.GiffleBuilder builder = new Giffle.GiffleBuilder()
.size(320, 480) // otuput image size 320x480
.delay(100) // 100 ms
.file(File.createTempFile("PicCollage", "gif"));
final Giffle encoder = builder.build();
List<Bitmap> bitmaps = getOutputBitmaps(); // please impelemnt this block by youself
int[] colors = getTrainingPixels(bitmaps, pw, ph, totalFrame, frameMs); // this part is tricky
encoder.GenPalette(colors.length, colors);
for (Bitmap bm : bitmaps) {
encoder.AddFrame(bm);
private Task<WeatherResult> queryWeather() {
final TaskCompletionSource<WeatherResult> task = new TaskCompletionSource<>();
Awareness.SnapshotApi.getWeather(mApiClient)
.setResultCallback(new ResultCallback<WeatherResult>() {
@Override
public void onResult(@NonNull WeatherResult weatherResult) {
if (!weatherResult.getStatus().isSuccess()) {
task.setError(new IllegalStateException("Could not get weather."));
return;
}