Skip to content

Instantly share code, notes, and snippets.

View nitindhar7's full-sized avatar

Nitin Dhar nitindhar7

View GitHub Profile
@nitindhar7
nitindhar7 / command_pattern_restautant_example.java
Created September 25, 2011 22:04
Command Pattern: Restaurant Example
// Client
class Customer {
// places an order (requesting a command)
}
// Command
class Order {
// waiter places this
}
@nitindhar7
nitindhar7 / gist:1241270
Created September 25, 2011 22:41
Command Pattern: Student Enrollment
// Client
class Student {
private int studentId;
public void requestEnrollment(int courseId) {
Enroll enroll = new Enroll(studentId, courseId);
Invoker invoker = new Invoker();
invoker.request(enroll);
}
@nitindhar7
nitindhar7 / gist:1241293
Created September 25, 2011 23:02
Abstracting Scripts: Template Method Pattern
abstract class AbstractScriptTemplate {
// Template Method Pattern
public final void runScript() {
setup();
scriptLogic();
clean();
report();
}
@nitindhar7
nitindhar7 / gist:1291838
Created October 17, 2011 02:58
Splitting animated gif files using Imagemagick
$ convert wait.gif[0] wait_0.gif
$ convert wait.gif[1] wait_1.gif
$ convert wait.gif[2] wait_2.gif
$ convert wait.gif[3] wait_3.gif
$ convert wait.gif[4] wait_4.gif
$ convert wait.gif[5] wait_5.gif
@nitindhar7
nitindhar7 / wait.xml
Created October 17, 2011 03:06
Animation frames in the res/drawable/ folder
<animation-list android:oneshot="false">
<item android:drawable="@drawable/wait_0" android:duration="50" />
<item android:drawable="@drawable/wait_1" android:duration="50" />
<item android:drawable="@drawable/wait_2" android:duration="50" />
<item android:drawable="@drawable/wait_3" android:duration="50" />
<item android:drawable="@drawable/wait_4" android:duration="50" />
<item android:drawable="@drawable/wait_5" android:duration="50" />
</animation-list>
@nitindhar7
nitindhar7 / gist:1291855
Created October 17, 2011 03:08
Starting an animation using split frames from an animated gif
ImageView spinner = (ImageView) findViewById(R.id.spinner);
spinner.setBackgroundResource(R.drawable.spinner);
AnimationDrawable frameAnimation = (AnimationDrawable) spinner.getBackground();
frameAnimation.start()
@nitindhar7
nitindhar7 / gist:1305327
Created October 22, 2011 00:20
Forrst API Java wrapper usage
import com.forrst.api;
ForrstAPI forrst = new ForrstAPIClient();
// API stats
forrst.stats();
// Authentication
forrst.usersAuth("USERNAME", "PASSWORD");
@nitindhar7
nitindhar7 / gist:1305331
Created October 22, 2011 00:22
Build Forrst API Java lib
$ ant
@nitindhar7
nitindhar7 / gist:1305333
Created October 22, 2011 00:24
Array Agg PSQL
SELECT user.id AS user_id, ARRAY_AGG(group.id) AS group_ids
FROM users
LEFT JOIN groups ON group.user_id = group.id
GROUP BY user.id
@nitindhar7
nitindhar7 / gist:1305345
Created October 22, 2011 00:31
Git autocomplete
curl https://github.com/git/git/raw/master/contrib/completion/git-completion.bash -OL