Skip to content

Instantly share code, notes, and snippets.

@harshulj
harshulj / installing-express.bash
Last active March 3, 2017 04:08
Installing Express.js
#Create a directory to hold the application. Lets call the application rail
$ mkdir rail
$ cd rail
# Now we’ll initialise a npm project. Use the following command for initialising. This command will create package.json file in the directory which will hold information about rail package and its dependency and meta data.
$ npm init
# Next task is to install express for this project. Don’t forget to use — save which adds Express as a dependency in package.json.
$ npm install express — save
// As per the question I am assuming that 1,3,4 should appear together anywhere in the array of numbers
arr = [-1, 0, 1, 3, 4, 7, 9]
'134' in ''.join(map(str, arr))

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@harshulj
harshulj / friendly_urls.markdown
Created January 4, 2012 17:51 — forked from jcasimir/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.