Skip to content

Instantly share code, notes, and snippets.

<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 June 11, 2013 18:14
Setting up local timers in fragments/activities
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 15:36
Using an AsyncLoader with ActiveAndroid
/*
* 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 April 28, 2021 07:25
3d rotation animation for Android
/*
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 December 14, 2015 19:49
Compojure example with Enlive template inheritance
(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 August 25, 2012 17:02
Bookmarklet to support html5 drag/drop image/file password generation
<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 17:01 — forked from gudbergur/README.markdown
Bootstrap's Typeahead plugin extended (allowing for AJAX functionality) among other things

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 January 8, 2012 06:33
Prim's Algorithm
// 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 = {};
@methodin
methodin / viterbi.js
Created January 7, 2012 21:59
Viterbi
// 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];
@methodin
methodin / markovCluster.js
Created January 7, 2012 03:54
Markov Clustering
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;
};