Skip to content

Instantly share code, notes, and snippets.

@PifyZ
PifyZ / friendly_urls.markdown
Last active August 29, 2015 14:25 — forked from CyberLight/friendly_urls.markdown
Friendly URLs in Rails

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.

@PifyZ
PifyZ / STLC.idr
Last active August 29, 2015 14:25 — forked from david-christiansen/STLC.idr
data Typ =
IntTyp
| BolTyp
| FunTyp Typ Typ
toType : Typ -> Type
toType IntTyp = Integer
toType BolTyp = Bool
toType (FunTyp x y) = toType x -> toType y
@PifyZ
PifyZ / learn.lua
Created February 26, 2014 08:57 — forked from tylerneylon/learn.lua
-- Two dashes start a one-line comment.
--[[
Adding two ['s and ]'s makes it a
multi-line comment.
--]]
----------------------------------------------------
-- 1. Variables and flow control.
----------------------------------------------------
@PifyZ
PifyZ / baseClass.js
Created February 24, 2014 15:19 — forked from dalgard/Class.js
// The base constructor (can be left empty, but a nice boilerplate might look like this)
function Class(properties) {
if (properties) {
// Add properties to the instance
Object.getOwnPropertyNames(properties).forEach(function (property_name) {
var descriptor = Object.getOwnPropertyDescriptor(properties, property_name);
Object.defineProperty(this, property_name, descriptor);
}, this);
}
}