Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
ARGV.each do |path|
files = Dir.glob(File.join(path, '**', "*.{jpg}"), File::FNM_CASEFOLD).each do |f|
puts File.path(f)
end
end
int sum(List<Integer> nums) {
int sum = 0;
for(Integer i: sums) {
sum+=i
}
return sum;
}
int myFactorial( int integer)
{
if( integer == 1)
return 1;
else
{
return(integer*(myFactorial(integer-1);
}
}
class Idea < ActiveRecord::Base
attr_accessible :title, :note
has_and_belongs_to_many :tags
def tags_attributes(hash)
hash.each do |sequence, tag_values|
tags.find_or_create_by_name(tag_values[:name])
end
end
repo = Repo.init_bare("public/git/myrepo.git")
fname = Time.now.to_i.to_s
File.open("public/git/" + fname, 'w') {|f| f.write('hello git' + fname)}
repo.add(fname)
repo.commit_index('my commit')
logger.info repo.commits
CGPoint touchLocation = CCDirector.sharedDirector().convertToGL(CGPoint.make(ev.getX(), ev.getY()));
if(touchLocation.x > largestX || touchLocation.x < smallestX) {
if(!(touchLocation.y > largestY || touchLocation.y < smallestY)) {
sprite.setPosition(sprite.getPosition().x, touchLocation.y);
}
} else if(touchLocation.y > largestY || touchLocation.y < smallestY) {
if(!(touchLocation.x > largestX || touchLocation.x < smallestX)) {
sprite.setPosition(touchLocation.x, sprite.getPosition().y);
}
float largestX = dirtyFoot.getPosition().x + (dirtyFoot.getContentSize().getWidth()/2);
float smallestX = dirtyFoot.getPosition().x - (dirtyFoot.getContentSize().getWidth()/2);
float smallestY = dirtyFoot.getPosition().y - (dirtyFoot.getContentSize().getHeight()/2);
float largestY = dirtyFoot.getPosition().y + (dirtyFoot.getContentSize().getHeight()/2);
MobileBackend::Application.routes.draw do
devise_for :posts
devise_for :users, :controllers => { :sessions => "sessions" }
devise_scope :user do
# namespace :api do
# namespace :v1 do
resources :sessions, :registration, :only => [:create, :destroy]
# end
# end
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :token_authenticatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :authentication_token
end
class SessionsController < Devise::SessionsController
def create
respond_to do |format|
format.html { super }
format.json {
warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
# render :status => 200, :json => { :error => "Success" }
render :status => :ok, :json => { :response => 'ok', :auth_token => User.authentication_token }
}