Skip to content

Instantly share code, notes, and snippets.

View sameera207's full-sized avatar

Sameera (Sam) sameera207

  • Sydney
View GitHub Profile
count = 0
a = Dir.glob("/<rails app path>/app/models/**/*.rb")
a.each do |f|
file = File.new(f)
@sameera207
sameera207 / gist:c0b9f89fa326bb23ff23
Last active August 29, 2015 14:05
Explanation for Regexp.new(search)
#Following is the problem with your solution. You have 2 if's , in ruby we need only 1 if
# notice that it has only one IF :)
if matched_games.length > 0 && matched_games.include?(search)
puts "Game #{search} found."
end
#clarrifications
Regexp.new(search) #is creating a new regular expression object in ruby.
#<Any Object>.new is the way of initializing an object in ruby. In this case 'Regexp' class.
#Regular expression can me used to match words in different options. Like
=== Managing the database in a Rails application ===
=== Rails migrations ===
In ruby/rails projects , the standard way of hadling database changes (add/edit tables, add/edit columns etc..)
through the migrations. this way we can hadle database changes easily.
=== where are the migrations ===
migrations are in the following folder
```ruby
@sameera207
sameera207 / accept nested attributes with rails4
Created October 13, 2014 02:40
accept nested attributes with rails4 strong params
class ItemsController < ApplicationController
#rest of your methods
# ......
private
def item_params
params.require(:item).permit(
:name,
:content,
:image,
:address,
@sameera207
sameera207 / gist:4cf93cb65970eac6f92c
Created March 3, 2015 09:33
Using Custom URL Schemes In Your Ionic Framework App
// link <a title="recipe" href="sampleapp://recipes/3">recipe</a>
//app.js
function handleOpenURL(url) {
setTimeout(function() {
window.location.hash = '/app/show/' + url.split("/").pop();
}, 500);
}
// following is my router
@sameera207
sameera207 / pages
Created October 11, 2011 14:44
patch for radiant-ck_editor_filter-extension
:javascript
Event.observe(window,'load',function(){
instantiateCkEditor('#{page_part.name.downcase}')
Event.addBehavior({ 'a.insert_asset': InsertIntoCk })
})
Event.observe($('part_#{page_part.name.downcase}_filter_id'),'change',function(){ toggleEditor('#{page_part.name.downcase}') })
@sameera207
sameera207 / page-parts
Created October 11, 2011 14:43
ck-editor-filter - patch1
:javascript
Event.observe(window,'load',function(){
instantiateCkEditor('#{page_part.name.downcase}')
Event.addBehavior({ 'a.insert_asset': InsertIntoCk })
})
Event.observe($('part_#{page_part.name.downcase}_filter_id'),'change',function(){ toggleEditor('#{page_part.name.downcase}') })
@sameera207
sameera207 / gist:2496320
Created April 26, 2012 05:46
re-naming all the erb templates in a directory
for i in *.erb; do mv "$i" "`basename $i .erb`.erb.old"; done
@sameera207
sameera207 / gist:2633710
Created May 8, 2012 08:56
HABTM - code sample
class Treatment
has_many :treatment_treatment_types
has_many :treatment_types, :through => :treatment_treatment_types
end
class TreatmentTypes
has_many :treatment_treatment_types
has_many :treatments, :through => :treatment_treatment_types
end