Skip to content

Instantly share code, notes, and snippets.

View j0an's full-sized avatar

Juan Manuel Garcia Olivares j0an

View GitHub Profile
@lgueye
lgueye / validate-es-behaviour.sh
Created February 7, 2012 14:45
elasticsearch : dealing with case and accents
# delete index (will print an error if 'my_index' doesn't exist, you can safely ignore it)
curl -XDELETE 'http://localhost:9200/my_index'
# create index with its settings
curl -XPOST 'http://localhost:9200/my_index' -d '{
"index.analysis.analyzer.default.type":"custom",
"index.analysis.analyzer.default.tokenizer":"standard",
"index.analysis.analyzer.default.filter.0":"lowercase",
"index.analysis.analyzer.default.filter.1":"asciifolding"
}'
@jcasimir
jcasimir / friendly_urls.markdown
Created September 11, 2011 15:48
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.

@stammy
stammy / wordpress_importer.rb
Last active March 27, 2022 09:39
Import a WordPress database and generate markdown files for Jekyll
# View my Jekyll blog http://paulstamatiou.com and my jekyll migration post http://paulstamatiou.com/how-to-wordpress-to-jekyll/
#
#
# based on the import script by icebreaker, which is based on mojombo's
# https://github.com/mojombo/jekyll/blob/master/lib/jekyll/migrators/wordpress.rb
# https://gist.github.com/303570
# edited to rewrite image URLs to use my CloudFront URL
require 'rubygems'
require 'sequel'
class VisitorStats
def initialize
@redis = Redis.new
end
# every time there's a hit, increment a counter for the
# day and week, and add the session id to a set of unique
# vistitors for the day/week
def hit(session_id)
today = Date.today