Skip to content

Instantly share code, notes, and snippets.

View johanbrook's full-sized avatar
🌴

Johan Brook johanbrook

🌴
View GitHub Profile
public void init() {
final AsyncTask<String, Void, Document> t = new ParseTextTask().execute(new String[] {"http://google.com"});
}
private class ParseTextTask extends AsyncTask<String, void, Document> {
@Override
protected Document doInBackground(String... params) {
return Jsoup.connect(params[0]).get();
/*
=RESPONSIVE STYLES
by Johan Brook for Macpro.se
--------------------------------------------- */
@media only screen and (max-width: 900px) {
#page {
margin: 0 5%;
max-width: none;
font-size: 1.6rem;
@johanbrook
johanbrook / gist:5285290
Last active December 15, 2015 15:58
Quick user style for putting the sidebar to the right in new Facebook design.
._6nw._4g5r .fbPageBannerInner, html ._6nw._4g5r #blueBarHolder #blueBar {
margin-left: -205px !important;
}
body._4g5r .fbChatSidebar {
left: auto !important;
right: 0 !important;
}
._4_37 {
@johanbrook
johanbrook / gist:5135182
Created March 11, 2013 15:47
Quicksort pseudo code
quick_sort(f, left, right) ->
return if right < left
first, last = f.first, f.last
pivot = (first + last) / 2
middle = _partition(f, 0, last, pivot)
swap(middle, pivot, f)
/**
* A path between to a node, with a weight and stored
* reference for a path from a start node.
*/
private class ComparableDijkstraPath<V extends Edge>
implements Comparable<ComparableDijkstraPath<V>> {
/**
* The reached node
*/
@Test
public void testBinarySqrt() {
double number = 2;
double delta = 10E-6;
double ourResult = Uppg2.binarySqrt(number, delta);
double mathResult = Math.sqrt(number);
System.out.println("Our result: "+ ourResult);
System.out.println("Math.sqrt(): " + mathResult);
# PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
# gem install pg
# On Mac OS X with macports:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
/**
* Where all the action is. Listens to card clicks.
*/
public void actionPerformed(ActionEvent e){
// Handle the New game and Quit button events:
String action = e.getActionCommand();
if("new".equals(action) && !timer.isRunning()){
nyttSpel();
// Fetch and set the IMDb ID stored in the title field
String imdbID = (String) this.titleField.getTag();
if(imdbID != null) {
movie.setImdbID(imdbID);
}
// Insert into database
ContentValues movieValues = new ContentValues();
movieValues.put(MoviesTable.COLUMN_TITLE, movie.getTitle());
movieValues.put(MoviesTable.COLUMN_RATING, movie.getRating());
/**
* Get the nth prime number.
*
* @param n A number
* @return The nth prime number
*/
public static int prime(int n) {
int counter = 0;
int number = 1;