Skip to content

Instantly share code, notes, and snippets.

View alexvbush's full-sized avatar

Alex Bush alexvbush

View GitHub Profile
@alexvbush
alexvbush / custom_daemon_start_stop.rb
Created June 22, 2011 21:03
how to start and stop custom daemon in Rails. According to Ryan Bates.
RAILS_ENV=development lib/daemons/mailer_ctl start
RAILS_ENV=development lib/daemons/mailer_ctl stop
@alexvbush
alexvbush / decimal_to_binary.rb
Created June 23, 2011 23:44
function to convert decimal to binary in Ruby.
def dec2bin(number)
number = Integer(number)
if(number == 0) then 0 end
ret_bin = ""
while(number != 0)
ret_bin = String(number % 2) + ret_bin
number = number / 2
end
ret_bin
@alexvbush
alexvbush / run_perl_python_scipts_in_rails.rb
Created July 19, 2011 22:08
How to run Perl and Python scripts in a Rails app.
#This will run Perl and Python scripts respectively in Rails console using 'gem escape'. Gem Escape allows to format path to the scripts properly.
perl_cmd = Escape.shell_command(['perl', "#{RAILS_ROOT}/bin/test_perl_script.pl"]).to_s
system perl_cmd
python_cmd = Escape.shell_command(['python', "#{RAILS_ROOT}/bin/test_python_script.py"]).to_s
system python_cmd
@alexvbush
alexvbush / Activity's Inner Class implements View.OnClickListener.
Created September 9, 2011 09:00
Activity implements various OnClickListeners.
package com.smartcloudcompany.onclickinxml;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class AndroidOnClickDefinitionInXMLActivity extends Activity implements OnClickListener {
@alexvbush
alexvbush / ActivityImplementsOnClickListener.java
Created September 9, 2011 09:38
Android various definition of OnClickListeners.
public class AndroidOnClickDefinitionInXMLActivity extends Activity implements OnClickListener {
private Button buttonWithActivityAsListener;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
@alexvbush
alexvbush / calculate_folder_size.rb
Created September 23, 2011 11:35
Recursively calculates the size of a folder(path to folder is the first input in terminal). Found other solutions using system calls but decide to write my own.
if ARGV.count != 1 || !File.directory?(ARGV[0])
p 'Please specify a folder.'
exit
end
def calculate_size(file)
#p 'calculating ' + file
if File.directory? file
@alexvbush
alexvbush / UIAlertViewPopupExample.m
Created January 27, 2012 07:26
iOS UIAlertView popup
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Some Title Here"
message:@"And some description message here"
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles: nil] autorelease];
[alert show];
FactoryGirl.define do
factory :post do
sequence(:post_title) {|n| "Post#{n}"}
post_date { Time.now - 10.days }
post_date_gmt { (Time.now - 10.days).gmtime }
post_modified { Time.now - 10.minutes }
post_modified_gmt { (Time.now - 10.minutes).gmtime }
post_status {"publish"}
factory :artist, :class => 'Artist' do
@alexvbush
alexvbush / AndroidWeakRefExample.java
Last active July 6, 2016 18:57
An example of how to store an Android Context object in a weak reference to avoid unexpected retain loops in adapters and such.
public class ExampleWeak {
private WeakReference<Context> weakContext;
public ExammpleWeak(Context context) {
this.weakContext = context;
}
public Context getContext() {
return weakContext.get();
}
@alexvbush
alexvbush / CollectionTest.java
Created November 17, 2013 07:14
An example of a custom collection class that you can use to iterate over your own collection object using for_each loop. The key ingredient is Iterable, and Iterator interfaces implemented in CustomCollectionWrapper class.
/**
*
*/
/**
* Smart Cloud, Inc. Nov 14, 2013.
* @author Alex Bush
*
*/
public class CollectionTest {