Skip to content

Instantly share code, notes, and snippets.

@sher
sher / base_model.rb
Created March 25, 2011 09:25
Tableless models in Rails 3
class BaseModel < ActiveRecord::Base
def self.columns
@columns ||= [];
end
def self.column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
end
def save(validate = true)
equire File.join(File.dirname(__FILE__), 'boot')
RAILS_GEM_VERSION = '2.3.9' unless defined? RAILS_GEM_VERSION
Rails::Initializer.run do |config|
config.time_zone = 'UTC'
config.gem 'declarative_authorization', :source => 'http://gemcutter.org'
config.gem 'searchlogic'
@sher
sher / gist:921693
Created April 15, 2011 13:34 — forked from Znow/gist:921691
- @employees.each do |employee|
%span{:style=>"float:left;margin-right:20px;"}= image_tag employee.image
%div{:style=>"float:left;margin-top:30px;"}
= employee.name
,
= employee.title
%br/
%br/
= mail_to employee.email
# Equipment model
class Equipment < ActiveRecord::Base
def price
read_attribute(:price).to_i
end
end
# Form _form.erb
<%= f.fields_for :equipment do |builder| -%>
<%= render "equipment_fields", :f => builder %>
@sher
sher / nginx
Created August 20, 2011 01:29
nginx init.d script
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
module DatatablesRails
class Structify
attr_accessor :struct
def initialize(data)
@struct = {}
@struct = data.collect{|d| d.attributes }
end
def formatter(&block)
#block.call(@struct)
#!/bin/bash
# CentOS rbenv system wide installation script
# Forked from https://gist.github.com/1237417
# Installs rbenv system wide on CentOS 5/6, also allows single user installs.
# Install pre-requirements
yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel \
make bzip2 autoconf automake libtool bison iconv-devel git-core
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>
<meta name="description" content="Something" />
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body ng-app="app" ng-controller="AppCtrl">
@sher
sher / gist:23ed544e29804ad24a11
Created June 27, 2015 04:06
Styled React component mixin with reference counting
function _mount(style, styles) {
for (var i = 0; i < styles.length; i++) {
if (style == styles[i].getAttribute('href')) {
styles[i].dataset.refc++;
return;
}
}
var newStyle = document.createElement('link');
newStyle.setAttribute('rel', 'stylesheet');
1: 日
2: 一
3: 国
4: 会
5: 人
6: 年
7: 大
8: 十
9: 二
10: 本