Skip to content

Instantly share code, notes, and snippets.

@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);
@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 / 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 / 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 / google_calendar_colors.rb
Created March 14, 2012 15:03
Google calendar colors
COLORS = %w[#AC725E #D0CF64 #F83A22 #FA573C #FF7537 #FFAD46 #42D692 #16A765 #7BD148 #B3DC6C #FBE983 #FAD165 #92E1C0 #9FE1E7 #9FC6E7 #4986E7 #9A9CFF #B99AFF #C2C2C2 #CABDBF #CCA6AC #F691B2 #CD74E6 #A47AE2]
@alvinsj
alvinsj / days_week_masking.rb
Created March 14, 2012 12:38
Mask days of week into binary, save to integer field
DAYS = %w[0 1 2 3 4 5 6 7]
DAYS_HUMAN = %w[Sun Mon Tue Wed Thur Fri Sat]
def days=(days)
self.days_mask = (days & DAYS).map { |r| 2**DAYS.index(r) }.sum
end
def days
DAYS.reject do |r|
((days_mask || 0) & 2**DAYS.index(r)).zero?
@alvinsj
alvinsj / group_sequence.rb
Created March 14, 2012 12:34
Group continuos sequences in an array
def group_sequence(seq)
return [] if seq.size == 0
g = Array.new
sub = Array.new
sub << seq[0]
if seq.size > 2
(seq[1..-1]).each do |s|
if s -sub[-1] == 1
sub << s
@alvinsj
alvinsj / group_by_word.coffee
Created March 9, 2012 10:05
[jquery] group by word
$.group_by_word = (ul_class, sortable, sub_string_count=0)->
$('ul.group').empty()
count = 0
word = ''
$("ul.#{ul_class} li").each (index, li_el) ->
# get attributes
@alvinsj
alvinsj / sort_then_group_by_character.coffee
Created March 9, 2012 09:33
[jquery] sort then group by character
$.sort_then_group_by_character = (sortable, ul_class)->
$.sort_by_words(ul_class, sortable)
$('ul.group').empty()
count = 0
character = ''
$("ul.#{ul_class} li").each (index, li_el) ->