Skip to content

Instantly share code, notes, and snippets.

@kenleycapps
kenleycapps / gist:1643546
Created January 19, 2012 22:57
Java Stacks as Lists
// Declare stack, push two strings
final Stack<String> strings = new Stack<String>();
final String test1 = "Test!";
final String test2 = "Test again!";
strings.push(test1);
strings.push(test2);
// Pop second string off
final String pop = strings.pop();
assertSame(test2, pop);
@kenleycapps
kenleycapps / MainActivity.java
Created November 23, 2011 00:20
Lots of Lists Part 2: MainActivity.java
package com.learnandroid.listviewtutorial.adapter;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
@kenleycapps
kenleycapps / news_entry_list_item.xml
Created November 22, 2011 23:18
Lots of Lists Part 2: news_entry_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Layout for individual news entries in a list -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Icon shown next to the title/subtitle -->
<ImageView
android:id="@+id/news_entry_icon"
@kenleycapps
kenleycapps / NewsEntryAdapter.java
Created November 22, 2011 23:07
Lots of Lists Part 2: NewsEntryAdapter
package com.learnandroid.listviewtutorial.adapter;
import java.text.DateFormat;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
@kenleycapps
kenleycapps / NewsEntry.java
Created November 22, 2011 22:08
Lots of Lists Part 2: NewsEntry
package com.learnandroid.listviewtutorial.adapter;
import java.util.Date;
/**
* Encapsulates information about a news entry
*/
public final class NewsEntry {
private final String title;
@kenleycapps
kenleycapps / main.xml
Created November 22, 2011 20:38
Lots of Lists Part 2: main.xml listview
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
@kenleycapps
kenleycapps / main.xml
Created November 22, 2011 18:29
Lots of Lists Part 2: main.xml start
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
@kenleycapps
kenleycapps / MainActivity.java
Created November 22, 2011 18:24
LotsOfListsPart2-MainActivity
package com.learnandroid.listviewtutorial.adapter;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@kenleycapps
kenleycapps / gist:1030878
Created June 17, 2011 04:31
Sum of multiples to 1000 (Python)
def sumOfMultiples( base, maximum ):
a = maximum / base
b = (a * (a+1)) / 2
return (b * base)
if __name__ == "__main__":
threes = sumOfMultiples( 3, 999 )
fives = sumOfMultiples( 5, 999 )
fifteens = sumOfMultiples( 15, 999 )
@kenleycapps
kenleycapps / gist:1030875
Created June 17, 2011 04:31
Sum of multiples to 1000
int sum = 0;
for(int i = 0; i < 1000; i++) {
if( (i % 3) == 0 || (i % 5) == 0 ) {
sum += i;
}
}
printf("Sum is: %d\n", sum);
return 0;