Skip to content

Instantly share code, notes, and snippets.

@mderazon
mderazon / app.js
Last active December 26, 2015 23:19
i18n simple express server
var express = require('express');
var app = express();
app.set('views', __dirname + '/views');
app.get('/', function(req, res) {
console.log('Hello i18n');
res.render('index.ejs');
});
@mderazon
mderazon / 0_reuse_code.js
Created October 30, 2013 09:04
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
<textarea name="my-xml-editor" data-editor="xml" rows="15"></textarea>
...
<textarea name="my-markdown-editor" data-editor="markdown" rows="15"></textarea>
...
<script src="//d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js"></script>
<script>
// Hook up ACE editor to all textareas with data-editor attribute
$(function () {
$('textarea[data-editor]').each(function () {
@mderazon
mderazon / MainActivity.java
Last active March 13, 2016 01:53
a main activity with the new ClearableAutoCompleteTextView and a method to toggle between the visibility of the the search icon and the search box
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ......
// ......
ActionBar actionBar = getSupportActionBar(); // you can use ABS or the non-bc ActionBar
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_HOME
| ActionBar.DISPLAY_HOME_AS_UP); // what's mainly important here is DISPLAY_SHOW_CUSTOM. the rest is optional
LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@mderazon
mderazon / ClearableAutoCompleteTextView.java
Last active November 30, 2018 16:42
a sub class of AutoCompleteTextView that has a dismiss button with OnClearListener when the clear button is clicked
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AutoCompleteTextView;
/**
* sub class of {@link android.widget.AutoCompleteTextView} that includes a clear (dismiss / close) button with
* a OnClearListener to handle the event of clicking the button
@mderazon
mderazon / search adapter.java
Created September 21, 2013 21:20
adapter for autocomplete search box
// adapter for the search dropdown auto suggest
ArrayAdapter<JSONObject> searchAdapter = new ArrayAdapter<JSONObject>(this, android.R.id.text1) {
private Filter filter;
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = this.getLayoutInflater().inflate(R.layout.search_item, parent, false);
}
TextView venueName = (TextView) convertView
@mderazon
mderazon / venueFilter.java
Last active December 23, 2015 15:18
venue filter
private class VenueFilter extends Filter {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
List<JSONObject> list = new ArrayList<JSONObject>(venues);
FilterResults result = new FilterResults();
String substr = constraint.toString().toLowerCase();
// if no constraint is given, return the whole list
if (substr == null || substr.length() == 0) {
result.values = list;
@mderazon
mderazon / main activity search.java
Last active December 23, 2015 15:09
how to put the search box in the actionbar
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ......
// ......
ActionBar actionBar = getSupportActionBar(); // you can use ABS or the non-bc ActionBar
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_HOME
| ActionBar.DISPLAY_HOME_AS_UP); // what's mainly important here is DISPLAY_SHOW_CUSTOM. the rest is optional
LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@mderazon
mderazon / search_item.xml
Last active December 23, 2015 15:09
search item
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAlignment="gravity" >
<TextView
android:id="@+id/search_item_venue_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@mderazon
mderazon / actionbar_search.xml
Last active December 23, 2015 15:09
The AutoCompleteTextView that goes into the ActionBar
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_horizontal"
android:focusable="true" >
<AutoCompleteTextView
android:id="@+id/search_box"
android:layout_width="fill_parent"