Skip to content

Instantly share code, notes, and snippets.

@alvinsj
alvinsj / unique_id.js
Created April 16, 2012 08:27
webapp unique id for analytics
function adbotGetCookie(c_name) {
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name){return unescape(y);}
}
}
@alvinsj
alvinsj / actionview.java
Created May 25, 2012 09:42
ActionBarSherlock ActionView EditText bugfix
searchActionItem.setOnActionExpandListener(new
OnActionExpandListener() {
public boolean onMenuItemActionExpand(MenuItem item) {
searchText.post(new Runnable() {
public void run() {
searchText.requestFocusFromTouch();
InputMethodManager imm =
(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(searchText, 0);
}
@alvinsj
alvinsj / prefix.pch
Created December 4, 2012 03:41
support for NS_ENUM and NS_OPTIONS in iOS 5
#if (__cplusplus && __cplusplus >= 201103L && (__has_extension(cxx_strong_enums) || __has_feature(objc_fixed_enum))) || (!__cplusplus && __has_feature(objc_fixed_enum))
#define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
#if (__cplusplus)
#define NS_OPTIONS(_type, _name) _type _name; enum : _type
#else
#define NS_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type
#endif
#else
#define NS_ENUM(_type, _name) _type _name; enum
#define NS_OPTIONS(_type, _name) _type _name; enum
@alvinsj
alvinsj / startOtherAppActivity.java
Created January 11, 2013 04:56
calling other app activity
final Intent intent = new Intent();
ComponentName cName = new ComponentName
("package_name","package_name.class_name");
intent.setComponent(cName);
startActivity(intent);
.table-view {
width:100%;
height:100%;
overflow:scroll;
}
.table-view-cell{
width:100%;
height:30px;
border: 1px solid #c0c0c0;
cursor: pointer;
@alvinsj
alvinsj / application.js.coffee
Last active December 12, 2015 02:49
link_to_add_fields "Add Field", f, :fields
$(document).on 'click', 'form .remove_fields', (event) ->
$(this).prev('input[type=hidden]').val('1')
$(this).closest('fieldset').hide()
event.preventDefault()
$(document).on 'click', 'form .add_fields', (event) ->
time = new Date().getTime()
regexp = new RegExp($(this).data('id'), 'g')
$(this).before($(this).data('fields').replace(regexp, time))
event.preventDefault()
@alvinsj
alvinsj / .profile
Created February 4, 2013 07:56
"alias" for rails4
rails4(){ /PARENT_PATH_TO_RAILS/rails/railties/bin/rails "$@" ; }
@alvinsj
alvinsj / _breadcrumb.html.erb
Last active December 12, 2015 03:29
simple breadcrumb in rails
<ul class="breadcrumb" id="breadcrumb" >
<li>
<%= breadcrumbs.join("<span class='divider'>/</span></li><li>").html_safe %>
</li>
</ul>
<!DOCTYPE html>
<html>
<head>
<script>
window.onload = function() {
// Must be server-side images; non-origin images will result in a security exception
var images = ["img.jpg"];
for (var i=0;i<images.length;i++) {
thumbnailify(images[i]);