Skip to content

Instantly share code, notes, and snippets.

Reader in = new BufferedReader(new FileReader(fileName));
Input Source input = new InputSource(in);
DOMParser parser = new DOMParser();
int whatToShow = NodeFilter.SHOW_ALL;
NodeFilter filter = new NodeFilter() {
public short acceptNode(Node n) {
if (n.getNodeType() == Node.TEXT_NODE) {
if(((Text)n).getData().trim().length() == 0)
return NodeFilter.FILTER_REJECT;
}
@joesavak
joesavak / gist:734939
Created December 9, 2010 16:38
Linux Ubuntu update
apt-get update
@joesavak
joesavak / gist:734945
Created December 9, 2010 16:42
ruby install
root@joe-ubuntu-0930:/home# apt-get install ruby irb rdoc
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
irb1.8 libreadline-ruby1.8 libreadline5 libruby1.8 rdoc1.8 ruby1.8
Suggested packages:
graphviz ruby1.8-examples ri1.8
The following NEW packages will be installed:
irb irb1.8 libreadline-ruby1.8 libreadline5 libruby1.8 rdoc rdoc1.8 ruby ruby1.8
CREATE OR REPLACE FUNCTION getDelimRow(p_slct character varying, p_dlmtr character varying DEFAULT ','::character varying)
RETURNS character varying AS
$BODY$
DECLARE
cur1 refcursor;
lc_str VARCHAR(4000);
lc_colval VARCHAR(4000);
intervalNum INTEGER;
BEGIN
@joesavak
joesavak / gist:763584
Created January 3, 2011 15:41
Running scripts in Ruby
cmd = "#{SCRIPTS_HOME}/bin/run_load.sh #{SCRIPTS_CONFIG} #{@file.file_upload.path}";
logger.info cmd;
Open3.popen3(cmd) do |i, o , e|
logger.info "CMD STDOUT " << o.read
logger.info "CMD STDERR " << e.read
end
@joesavak
joesavak / gist:959233
Created May 6, 2011 16:00
jpeg & pjpeg
has_attached_file :user_pic, :styles => {
:thumb=>"50x50#"
},
:default_url => "/images/missing.png"
validates_attachment_size :user_pic, :less_than => 10.megabytes
validates_attachment_content_type :user_pic, :content_type => ['image/jpeg','image/jpg','image/png','image/gif','image/pjpeg']
@joesavak
joesavak / facebook.yml
Created May 20, 2011 19:53
facebook.yml
#config/facebook.yml
development:
app_id: 1158718570175
secret_key: aashfljkhaklasfasfd
app_key: sdgasdg435672456236
callback_url: http://localhost:3000/
test:
app_id: 1158718570175
secret_key: aashfljkhaklasfasfd
@joesavak
joesavak / koala.rb
Created May 20, 2011 19:54
koala.rb
# config/initializers/koala.rb
module Facebook
CONFIG = YAML.load_file(Rails.root + "config/facebook.yml")[Rails.env]
APP_ID = CONFIG['app_id']
SECRET = CONFIG['secret_key']
CALLBACK_URL = CONFIG['callback_url']
end
@joesavak
joesavak / facebook_migration.rb
Created May 20, 2011 19:58
facebook migration
class AddFbAccessTokenToUsers < ActiveRecord::Migration
def self.up
add_column :users, :fbaccess, :string
add_column :users, :fbusername, :string
add_column :users, :fb_uid, :bigint
end
def self.down
remove_column :users, :fbaccess
remove_column :users, :fbusername
<div id="fb-root"></div>
<%= javascript_include_tag 'fbconnect' %>
Auto-post on Facebook
<span id="fbusing" style="display:none;">using account
<span id="fbuser">
<a href="" onclick="window.open('http://www.facebook.com/settings/?tab=privacy','_blank');return false;" ><%= @user.fbusername%></a>
</span>
</span>
<span id ="connectwithfb">
<a href="" id="fbconnect"><%= image_tag("facebook-connect-button.png",:border=>0,:height=>18,:width=>120)%></a>