$ rails g model User
belongs_to
has_one
| ## just some ways to check if a url exists | |
| # method 1 - from Simone Carletti | |
| require "net/http" | |
| url = URI.parse("http://www.google.com/") | |
| req = Net::HTTP.new(url.host, url.port) | |
| res = req.request_head(url.path) | |
| # method 2 - from some kid on the internet | |
| require 'open-uri' |
| # Better each() for use with coffeescript | |
| # 1. Wraps child in jquery object | |
| # 2. Sets child first argument, so that fat-binding can be used. | |
| # 3. Sets @ as well, for normal binds | |
| jQuery.fn.loop = (block) -> | |
| for i in @ | |
| element = jQuery(i) | |
| res = block.call element, element | |
| break if res == false |
| <ul id="members" data-role="listview" data-filter="true"> | |
| <!-- ... more list items ... --> | |
| <li> | |
| <a href="detail.html?id=10"> | |
| <h3>John Resig</h3> | |
| <p><strong>jQuery Core Lead</strong></p> | |
| <p>Boston, United States</p> | |
| </a> | |
| </li> | |
| <!-- ... more list items ... --> |
| # include from an initializer | |
| module HstoreAccessor | |
| def self.included(base) | |
| base.extend(ClassMethods) | |
| end | |
| module ClassMethods | |
| def hstore_accessor(hstore_attribute, *keys) | |
| Array(keys).flatten.each do |key| |
| unless Rails.env.production? | |
| connection = ActiveRecord::Base.connection | |
| connection.tables.each do |table| | |
| connection.execute("TRUNCATE #{table}") unless table == "schema_migrations" | |
| end | |
| sql = File.read('db/import.sql') | |
| statements = sql.split(/;$/) | |
| statements.pop |
| #!/bin/bash | |
| ### BEGIN INIT INFO | |
| # Provides: sidekiq beta | |
| # Required-Start: $syslog $remote_fs | |
| # Required-Stop: $syslog $remote_fs | |
| # Should-Start: $local_fs | |
| # Should-Stop: $local_fs | |
| # Default-Start: 2 3 4 5 | |
| # Default-Stop: 0 1 6 | |
| # Short-Description: sidekiq beta - asynchronous rails |
| #!/bin/bash | |
| # sidekiq Init script for Sidekiq | |
| # chkconfig: 345 100 75 | |
| # | |
| # Description: Starts and Stops Sidekiq message processor for Stratus application. | |
| # | |
| # User-specified exit parameters used in this script: | |
| # | |
| # Exit Code 5 - Incorrect User ID | |
| # Exit Code 6 - Directory not found |
| // This script will boot app.js with the number of workers | |
| // specified in WORKER_COUNT. | |
| // | |
| // The master will respond to SIGHUP, which will trigger | |
| // restarting all the workers and reloading the app. | |
| var cluster = require('cluster'); | |
| var workerCount = process.env.WORKER_COUNT || 2; | |
| // Defines what each worker needs to run |
| app = angular.module 'BlogExample', [] | |
| # Simple controller that loads all blog posts | |
| app.controller 'BlogCtrl', ['$scope', 'Blog', ($scope, Blog) -> | |
| # Get all the blog posts | |
| Blog.all().then (posts) -> | |
| $scope.posts = posts | |
| # Extend the $scope with our own properties, all in one big block | |
| # I like this because it looks like declaring a class. |