Skip to content

Instantly share code, notes, and snippets.

View AlwinaO's full-sized avatar

Alwina Oyewoleturner AlwinaO

View GitHub Profile
@matthutchinson
matthutchinson / fakeout.rake
Created February 10, 2010 16:49
fakeout.rake - a simple/configurable rake task that generates some random fake data for the app (using faker) at various sizes
# a simple/configurable rake task that generates some random fake data for the app (using faker) at various sizes
# NOTE: requires the faker or ffaker gem
# sudo gem install faker - http://faker.rubyforge.org
# OR
# sudo gem install ffaker - http://github.com/EmmanuelOga/ffaker
require 'faker'
class Fakeout
@amscotti
amscotti / login.rb
Created November 22, 2011 00:45
Sample of Sinatra authentication
require 'rubygems'
require 'bcrypt'
require 'haml'
require 'sinatra'
enable :sessions
userTable = {}
helpers do
@markbates
markbates / script.md
Created December 21, 2012 18:21
Getting Started with Sinatra

In an earlier video we took a look at Rack to build incredibly lightweight web applications with Ruby. Rack's toolkit allowed us to quickly throw to get a working application, but we did have to put a little effort into it once we wanted to build something a little more complex.

Sometimes you want a fast and simple framework for building a simple web application. Perhaps you only need to respond to a handful of routes, or you want the response time for a small part of a bigger application to be lighting fast. The Sinatra framework is made for just these moments.

Today let's take a quick look at this framework and see how quickly we can build lightweight web applications.

To get started we first need to install the Sinatra gem:

gem install sinatra
@jwo
jwo / mysql.database.yml
Last active October 4, 2024 14:01
Sample config/database.yml from Rails. Postgres, MySQL, and SQLite
#
# Install the MYSQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
@labe
labe / Creating_User_Accounts_in_Sinatra.md
Last active October 27, 2022 04:24
Creating user accounts with Sinatra (no BCrypt)

##User accounts with Sinatra (no BCrypt)

Create migration

A very basic schema for a user typically looks like this:

def change
  create_table :users do |t|
 t.string :username
@clarkdave
clarkdave / pg_interval.rb
Last active July 9, 2019 00:57
Support for PostgreSQL `interval` type in Rails 4. Although ActiveRecord supports `interval` by default, it turns it into a string (and tells Postgres the column is type string, too). This means you don't get any proper interval goodness. By sticking this code into an initialiser, ActiveRecord will create proper `interval` column types in Postgr…
#
# This will force ActiveRecord to create proper `interval` column types in PostgreSQL
#
# def change
# add_column :leases, :period, :interval
# end
#
# This applies to a generated `schema.rb` file too.
#
# No special OID type is applied to an `interval` type. Rails will treat it as a string, although
@stevenyap
stevenyap / Simple Form.md
Created October 26, 2013 04:25
Simple Form Cheatsheet

Gemfile

gem 'simple_form'

Installation

rails generate simple_form:install
@itsmattsoria
itsmattsoria / gistfil1.textile
Last active October 13, 2024 22:55
Mac Terminal Cheat Sheet

SHORTCUTS

Key/Command Description
Tab Auto-complete files and folder names
Ctrl + A Go to the beginning of the line you are currently typing on
Ctrl + E Go to the end of the line you are currently typing on
Ctrl + U Clear the line before the cursor
Ctrl + K Clear the line after the cursor
Ctrl + W Delete the word before the cursor
Ctrl + T Swap the last two characters before the cursor
@cowboy-cod3r
cowboy-cod3r / ruby-datetime-format.rb
Created December 14, 2013 15:10
Ruby: Convert the Format of a Date
#!/opt/apps/ruby/ruby/bin/ruby
require 'date'
# The initial date format as a String
my_date = "2013-10-03 21:03:46Z"
# Convert the Date to a DateTime Object
date_obj = DateTime.strptime(my_date,'%Y-%m-%d %H:%M:%S%Z')
# Re-Format the date - returns a String
@christianesperar
christianesperar / Ruby Factorial Method
Created March 2, 2014 14:41
Ruby Factorial Method
class Integer
def factorial
result = 0
self.downto(1) { |number| result == 0 ? result = number : result *= number }
return result
end
end