Skip to content

Instantly share code, notes, and snippets.

@exallium
exallium / prefix_parser.py
Created August 8, 2013 13:02
Infix to prefix parser and evaluator I wrote in like 10 minutes (meaning don't judge me)
import sys
# Note ('s are not currently supported. Given we treat them as
# 'frames' they are implicitly simple to recursivly implement.
ops = ['^', '*', '/', '+', '-']
# 1 + 2 -> + 1 2
# 1 + 2 * 3 -> + * 3 2 1
def parser(tokens):
stack = []
@exallium
exallium / bf.c
Created February 24, 2014 05:23
BF Interpreter in C... Because I can. And I was a bit bored.
/**
* usage: ./bf "<program>"
* example: ./bf ",[>++<-]>. ; multiplies a number by 2"
*
* Brainfuck Interpreter
*
* BF has the following commands:
* > Move to next memory position
* < Move to prev memory position
* + Increment current memory position
@exallium
exallium / Function.java
Last active August 29, 2015 13:57
Very simple Function object with composition in Java.
public abstract class Function<A, B> {
public abstract B apply(A arg);
// Given f :: a -> b and g :: b -> c, we can define h :: a -> c as the composition of f and g
public static <A, B, C> Function<A, C> compose(final Function<A, B> x, final Function<B, C> y) {
return new Function<A, C>() {
@Override
public C apply(A arg) {
return y.apply(x.apply(a));
public abstract class ButterKnifeViewHolder(val itemView : View) {}
public fun <T : View> ButterKnifeViewHolder.bindView(id: Int): ReadOnlyProperty<Any, T> = ViewBinding(id)
public fun <T : View> ButterKnifeViewHolder.bindOptionalView(id: Int): ReadOnlyProperty<Any, T?> = OptionalViewBinding(id)
public fun <T : View> ButterKnifeViewHolder.bindViews(vararg ids: Int): ReadOnlyProperty<Any, List<T>> = ViewListBinding(ids)
public fun <T : View> ButterKnifeViewHolder.bindOptionalViews(vararg ids: Int): ReadOnlyProperty<Any, List<T>> = OptionalViewListBinding(ids)
@exallium
exallium / AutoCompleteCursorAdapter.java
Last active August 29, 2015 14:20
SugarDB Cursor Adapter for AutoComplete Widgets
package org.exallium.tradetracker.app.controller.adapters
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.Filter
import android.widget.Filterable
import android.widget.TextView
import com.orm.query.Condition
@exallium
exallium / datak.kt
Last active August 29, 2015 14:21
kotlinvsxtend
data class MyValueObject(val a: Int, val b: String)
package controller
public class Controller {
val editText : RxEditText<User> = // ...
val model : Model<User> = // ...
val modelObserver: Observer<User>? = null
val editTextObserver: Observer<User>? = null
@exallium
exallium / adapter.java
Last active August 29, 2015 14:25
flat
/* within adapter class */
private static class ItemDeletate<T> {
private final T item;
private boolean isViewed;
public ItemDelegate(T item) {
this.item = item;
}
@exallium
exallium / Action.java
Last active August 29, 2015 14:27
UndoCommand Pattern
public enum Action {
ACTION1, ACTION2
}
@exallium
exallium / build.workaround-missing-resources.gradle
Created September 18, 2015 14:27
Workaround Missing Resources for Robolectric 3.0
// Workaround for missing test resources when run unit tests within android
// studio.
// This copy the test resources next to the test classes for each variant.
// Tracked at https://github.com/nenick/AndroidStudioAndRobolectric/issues/7
// Original solution comes from
// https://code.google.com/p/android/issues/detail?id=136013#c10
// apply with:
// apply from: build.workaround-missing-resources.gradle
gradle.projectsEvaluated {