Skip to content

Instantly share code, notes, and snippets.

View samiron's full-sized avatar
🏠
Working from home

Samiron paul samiron

🏠
Working from home
View GitHub Profile
class Person
{
private String name ;
private int id;
/**
* Receives the name and set in instance variable
*/
public void setName(String name){
this.name = name;
@samiron
samiron / JaxpParsing.java
Created November 13, 2012 09:58
Jaxp Parsing Examples
package test.xml;
import java.io.InputStream;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
@samiron
samiron / XomParsing.java
Created November 13, 2012 06:48
XML Parsing Examples with XOM
package test.xml;
import java.io.IOException;
import java.io.InputStream;
import nu.xom.Nodes;
import nu.xom.Builder;
import nu.xom.Document;
import nu.xom.Element;
@samiron
samiron / 01_PerlParameters.rb
Created November 9, 2012 04:02
Play with Perl Parameters
sub sum{ doit('+', @_) }
sub fact{ mul(1..shift) }
sub mul{ doit('*', @_) }
sub doit
{
my ($d, @nums) = @_;
return eval( join($d, @nums) );
}
@samiron
samiron / application.js
Created October 14, 2012 16:42
Rails 3: Update fields via ajax
/*
This part of javascript needs to be included to make
a ajax call onchanging the selection value of dropdown.
Here, application.js is shown just for example. You should
load this based on your requirements.
*/
//Use the id of your dropdown instead of "dropdown_id"
$(function($) {
@samiron
samiron / user.rb
Created October 10, 2012 16:52
Rails 3: has_many :through
#FILE: models/user.rb
@samiron
samiron / cities_controller.rb
Created October 8, 2012 16:32
Rails 3: Ajax Link
#FILE: app/controllers/cities_controller.rb
class CitiesController < ApplicationController
#When you do a ajax request the respond handler is ':js'
#So format.js will work. To render a response the new.js.erb
#file will be used.
def new
@city = City.new
respond_to do |format|
@samiron
samiron / cities_controller.rb
Created October 5, 2012 18:24
Rails 3: Nested form_for child field_for parent
#Description: We want to show a region(parent) form
#while showing City information.
#If the form submitted with Region information,
# - New region will be created
# - City#region_id will have the new region id
def show
@city = City.find(params[:id])
@samiron
samiron / rails-2.3.2-example.rb
Created October 2, 2012 19:06
Rails 2.3.2 Routing Example
#config/routes.rb
map.route_a 'my_controller', :controller => "Users", :action => "a"
map.route_b 'my_controller/uid/:uid', :controller => "Users", :action => "b"
#Generated Links
route_a_url() ---> http://localhost:3000/my_controller
route_b_url(:uid => 10) ---> http://localhost:3000/my_controller/uid/10
#Requesting to the above url redirects two different actions
#Output of rake routes
@samiron
samiron / comments_controller.rb
Created September 19, 2012 07:26
Sample Rails Controller
class CommentsController < ApplicationController
# GET /comments
# GET /comments.json
def index
@comments = Comment.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @comments }
end