Skip to content

Commit

Permalink
Hello.
Browse files Browse the repository at this point in the history
  • Loading branch information
rstacruz committed Mar 16, 2012
0 parents commit 85cc0fe
Show file tree
Hide file tree
Showing 41 changed files with 3,816 additions and 0 deletions.
78 changes: 78 additions & 0 deletions Etc/PHP_Kohana.ctxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Installing
wget "http://kohanaphp.com/download?modules%5Bauth%5D=Auth&languages%5Ben_US%5D=en_US&format=zip" -O k.zip &&\
unzip -q k.zip && rm k.zip &&\
mv Kohana_*/* . && rm -rf Kohana_* &&\
rm -f "Kohana License.html" &&\
# htaccess
cat example.htaccess | sed 's/RewriteBase .*/RewriteBase \//g' > .htaccess && rm example.htaccess &&\
echo Done! Go and edit application/config/config.php and change the site stuff.

# Public HTML
mkdir -p public_html &&\
mv index.html public_html &&\
mv .htaccess public_html &&\
echo Done. Now edit index.html's paths

Git ignore
(echo \*.swo; echo \*.swp; echo .DS_Store; echo Thumbs.db; echo \*~; echo application/logs; echo application/cache ) > .gitignore &&\

# Database
$config['default'] = array
(
'benchmark' => TRUE,
'persistent' => FALSE,
'connection' => array
(
'type' => 'mysql',
'user' => 'leet', // set to db user name
'pass' => 'l33t', // set to db user password
'host' => 'localhost',
'port' => FALSE,
'socket' => FALSE,
'database' => 'leetdb' // set to db name
),
'character_set' => 'utf8',
'table_prefix' => '',
'object' => TRUE,
'cache' => FALSE,
'escape' => TRUE
);


// ORM model
class Post_Model extends ORM {
protected $has_one = array('user'); // has_many, belong_to, has_one, has_and_belongs_to_many
}

// ORM
$post = ORM::factory('post', 1);
$post->name = "Post name";
$post->save();
foreach ($post->categories as $category)
{
echo $category->name;
}

// Find (returns even if no row is found)
$o = ORM::factory('article')->find(1);
$o = ORM::factory('article')->where('title', $title)->find();
if (!$o->loaded) { die('Not found'); }
echo $o->title;

// Find_all
$o = ORM::factory('article')->find_all();
foreach ($o as $article) { echo $article->title; }

// ->$saved
// ->$changed[]
// ->$object_name (Blog_Post_Model => "blog_post")
// ->$primary_key ('id')
// ->$primary_val ('username') - more userfriendly identifier
// ->$table_name
// ->$ignored_columns = array('whatever')
// ->$table_columns = array('id', 'username')
// ->$sorting = array('last_login' => 'desc') -- default sorting

//


104 changes: 104 additions & 0 deletions Etc/Rails_2.ctxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Debug
logger.debug "xx"

# Controller stuff
class MyController < ApplicationController::Base
controller.response.body

# Filters
before_filter :require_login # Looks for require_login method
before_filter MyFilter # Looks for MyFilter class
before_filter { |ct| head(400) if ct.params["stop_action"] }
around_filter :catch_exceptions
after_filter :xx

layout "admin_area" # Looks for the view file
layout "admin_area", :except => [ :rss, :whatever ]
layout :foo # Looks for private function foo

private
def whatever ...

class MyFilter
def self.filter(controller, &block)

# Model

belongs_to :user
validates_presence_of :user
default_scope :order => 'id DESC'
named_scope :today, :conditions = "created_at x"
named_scope :today, lambda {{ :conditions = [ "created_at between ? and ?", 1.hour.ago.utc, 300.seconds.ago.utc ] }}
# Then you can call feed.today

# Controller methods
render :action => 'help', :layout => 'help'
render :text => 'so and so'
render :status => :created, :location => post_url(post) # With HTTP headers
redirect_to :action => 'index'
render :partial => 'product', :collection => @products, :as => :item, :spacer_template => "product_ruler"
return head(:method_not_allowed)
head :created, :location => '...'

url_for :controller => 'posts', :action => 'recent'

location = request.env["SERVER_ADDR"]

# For views
auto_discovery_link_tag(:rss, {:action => "feed"}, {:title => "RSS Feed"})
javascript_include_tag "foo"
stylesheet_link_tag
image_tag

# Ruby stuff!
# Defining a class method (not a typo)
Fixnum.instance_eval { def ten; 10; end }
Fixnum.ten # => 10

# Defining an instance method
Fixnum.class_eval { def number; self; end }
7.number #=> 7

# Multiple arguments, send()
class Klass
def hello(*args); "Hello " + args.join(' '); end
end
Klass.new.send :hello, "gentle", "readers"

def can(*args)
yield if can?(*args)
end
# can(x) {...} => if can?(x) {...}



# Struct
class Foo < Struct.new(:name, :email)
end

j = Foo.new("Jason", "[email protected]")
j.name = "Hi"
print j.name


# Struct
class Foo < Struct.new(:name, :email)
end

j = Foo.new("Jason", "[email protected]")
j.name = "Hi"
print j.name


# Method missing
def method_missing(method_name, *arguments)
if method_name.to_s[-1,1] == "?"
self == method_name.to_s[0..-2]


# Rails logger
Rails.logger.info("...")

# To string
:hello_there.to_s

4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source :rubygems

gem "proton", "~> 0.3.4"
gem "rack-cache", "~> 1.0.0"
41 changes: 41 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
GEM
remote: http://rubygems.org/
specs:
RedCloth (4.2.8)
chunky_png (1.2.1)
compass (0.11.5)
chunky_png (~> 1.2)
fssm (>= 0.2.7)
sass (~> 3.1)
cuba (2.0.1)
rack
tilt
fssm (0.2.7)
haml (3.1.3)
hashie (1.0.0)
maruku (0.6.0)
syntax (>= 1.0.0)
proton (0.3.4)
RedCloth (~> 4.2.3)
compass (~> 0.11.1)
cuba (~> 2.0.0)
haml (~> 3.1.1)
hashie (~> 1.0.0)
maruku (~> 0.6.0)
sass (~> 3.1.1)
shake (~> 0.1)
tilt (~> 1.3.2)
rack (1.3.2)
rack-cache (1.0.2)
rack (>= 0.4)
sass (3.1.7)
shake (0.1.3)
syntax (1.0.0)
tilt (1.3.3)

PLATFORMS
ruby

DEPENDENCIES
proton (~> 0.3.4)
rack-cache (~> 1.0.0)
12 changes: 12 additions & 0 deletions Protonfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This is a Proton site.
# Install Proton (`gem install proton`) and type `proton` for help.
requirement: 0.2

# The folder where the site's source files are kept.
site_path: .
output_path: _output

# Other paths:
layouts_path: _layouts
extensions_path: _extensions
partials_path: .
17 changes: 17 additions & 0 deletions _layouts/default.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="/style.css" rel="stylesheet" />
</head>
<body>
<h1><%= page.meta.title || File.basename(page.file, '.*').capitalize %></h1>
<%= yield %>

<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>
44 changes: 44 additions & 0 deletions _prettify.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* Pretty printing styles. Used with prettify.js. */

.str { color: #080; }
.kwd { color: #008; }
// .com { color: #607077; background: rgba(black, 0.05); padding: 1px 3px; @include border-radius(2px); }
.com { color: #7bd; text-shadow: 1px 1px 0 rgba(white, 0.3); }
.typ { color: #606; }
.lit { color: #066; }
.pun { color: #660; }
.pln { color: #000; }
.tag { color: #008; }
.atn { color: #606; }
.atv { color: #080; }
.dec { color: #606; }

/* Specify class=linenums on a pre to get line numbering */
ol.linenums { margin-top: 0; margin-bottom: 0 } /* IE indents via margin-left */
li.L0,
li.L1,
li.L2,
li.L3,
li.L5,
li.L6,
li.L7,
li.L8 { list-style-type: none }
/* Alternate shading for lines */
li.L1,
li.L3,
li.L5,
li.L7,
li.L9 { background: #eee }

@media print {
.str { color: #060; }
.kwd { color: #006; font-weight: bold; }
.com { color: #600; font-style: italic; }
.typ { color: #404; font-weight: bold; }
.lit { color: #044; }
.pun { color: #440; }
.pln { color: #000; }
.tag { color: #006; font-weight: bold; }
.atn { color: #404; }
.atv { color: #060; }
}
Loading

0 comments on commit 85cc0fe

Please sign in to comment.