Skip to content

Instantly share code, notes, and snippets.

View activity.xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/drawer_content_padding"/>
@methodin
methodin / TimerExample.java
Created Jun 11, 2013
Setting up local timers in fragments/activities
View TimerExample.java
public class DummyFragment extends Fragment {
private UpdateHandler handler;
private Timer timer;
@Override
public void onCreate(Bundle savedInstanceState) {
handler = new UpdateHandler(this);
super.onCreate(savedInstanceState);
}
@methodin
methodin / ListLoader.java
Created May 30, 2013
Using an AsyncLoader with ActiveAndroid
View ListLoader.java
/*
* Example:
* new ListLoader(listView).execute(new Select().from(TestEntity.class));
*/
import java.lang.ref.WeakReference;
import java.util.List;
import android.os.AsyncTask;
import android.widget.ListView;
@methodin
methodin / Rotate3dAnimation.java
Last active Apr 28, 2021
3d rotation animation for Android
View Rotate3dAnimation.java
/*
Original code found at:
https://code.google.com/p/android-stocker/source/browse/trunk/src/com/twofuse/stocker/Rotate3dAnimation.java?r=2
Use (in set):
Rotate3dAnimation skew = new Rotate3dAnimation(20, 0, 0, 0, 0, 0);
set.addAnimation(skew);
animation = new TranslateAnimation(0, 0, 0, 0, Animation.RELATIVE_TO_SELF, 0.5f, 0, 0);
set.addAnimation(animation);
@methodin
methodin / compojure-enlive.clj
Last active Dec 14, 2015
Compojure example with Enlive template inheritance
View compojure-enlive.clj
(ns list.handler
(:use compojure.core
ring.adapter.jetty
[net.cgrand.enlive-html :as html])
(:require [compojure.handler :as handler]
[compojure.route :as route])
(:gen-class))
(defmacro maybe-substitute
([expr] `(if-let [x# ~expr] (html/substitute x#) identity))
@methodin
methodin / bookmarklet.html
Created Aug 25, 2012
Bookmarklet to support html5 drag/drop image/file password generation
View bookmarklet.html
<a href="javascript:(function(){var head=document.getElementsByTagName('head')[0];var e=document.createElement('script');e.src='//crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/sha256.js';head.appendChild(e);e=document.createElement('style');e.innerHTML='.picpass-active {background:#aaffaa !important;z-index:10000}';head.appendChild(e);e=document.createElement('script');e.src='//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js';head.appendChild(e);var inter=setInterval(check,100);var runs=0;function check(){if(typeof jQuery!='undefined'){run();clearInterval(inter);}if(++runs>60){clearInterval(inter);}}function run(){var dropzone=$('input[type=password]');dropzone.css({'zIndex':10000});var dropped=null;var content=null;$('body').on('dragstart',function(e){if(e.srcElement.src){content=e.srcElement.src;}});dropzone.on('dragover',function(e){e.preventDefault();$(this).addClass('picpass-active');});dropzone.on('dragleave',function(e){e.preventDefault();$(this).removeClass('picpass-active');});dropzo
@methodin
methodin / README.markdown
Created May 2, 2012 — forked from gudbergur/README.markdown
Bootstrap's Typeahead plugin extended (allowing for AJAX functionality) among other things
View README.markdown

This is a fork of Bootstrap Typeahead that adds minimal but powerful extensions.

For example, process typeahead list asynchronously and return objects

  # This example does an AJAX lookup and is in CoffeeScript
  $('.typeahead').typeahead(
    # source can be a function
    source: (typeahead, query) ->
      # this function receives the typeahead object and the query string
@methodin
methodin / prims.js
Created Jan 8, 2012
Prim's Algorithm
View prims.js
// Represents an edge from source to sink with capacity
var Edge = function(source, sink, capacity) {
this.source = source;
this.sink = sink;
this.capacity = capacity;
};
// Main class to manage the network
var Graph = function() {
this.edges = {};
View viterbi.js
// Viterbi algorithm for finding hidden relationships
function Viterbi(data) {
var V = [{}];
var path = {};
// Initialize base cases (t == 0)
for(var i=0;i<data.states.length;i++) {
var state = data.states[i];
V[0][state] = data.start_probability[state] * data.emission_probability[state][data.observations[0]];
path[state] = [state];
View markovCluster.js
function round(n) {
return Math.round(n*100) / 100;
}
// Represents an edge from source to sink with capacity
var Edge = function(source, sink, capacity) {
this.source = source;
this.sink = sink;
this.capacity = capacity;
};