Skip to content

Instantly share code, notes, and snippets.

require 'rubygems'
require 'sinatra'
require 'fileutils'
# upload with:
# curl -v -F "data=@/path/to/filename" http://localhost:4567/user/filename
post '/:name/:filename' do
userdir = File.join("files", params[:name])
@efrenfuentes
efrenfuentes / gist:950109
Created April 30, 2011 23:53
Elixir event statements
from elixir.statements import Statement
from sqlalchemy.orm.mapper import MapperExtension
import types
def proxy_to_instance(name):
def new_func(self, mapper, connection, instance):
if hasattr(instance, name) : getattr(instance, name)()
return new_func
@efrenfuentes
efrenfuentes / numero_a_letras.rb
Created September 26, 2012 02:27
Numero a letras (Ruby)
module NumeroALetras
module Numeric
def self.included(recipiente)
recipiente.extend(ClassMethods)
recipiente.class_eval do
include InstanceMethods
end
end
end
@efrenfuentes
efrenfuentes / numero_letras.py
Created September 26, 2012 02:29
Numero a letras (Python)
#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'efrenfuentes'
MONEDA_SINGULAR = 'bolivar'
MONEDA_PLURAL = 'bolivares'
CENTIMOS_SINGULAR = 'centimo'

Authentication from Scratch with Rails 3.2.5

Rails 3.1 gives us a really easy way to authenticate users in our app: http_basic_authenticate_with. Using it, all we need to do is create a model for the user (certainly, User model :P) with an attribute called password_digest and some views feature for login and register users. After all, let's relax and let Rails do the hard work.

What we'll need

Gemfile

gem 'bcrypt-ruby', '~> 3.0.0'

Model

First at all, an User model which we can generate by following: rails g model user email:string password_digest:string and then add the following methodo call to generated class: has_secure_password

@efrenfuentes
efrenfuentes / Spanish.inflectors.rb
Last active March 13, 2018 12:57 — forked from maxidr/Spanish.inflectors.txt
Spanish inflectors for rails 3
ActiveSupport::Inflector.inflections do |inflect|
inflect.plural /([aeiou])([A-Z]|_|$)/, '\1s\2'
inflect.plural /([rlnd])([A-Z]|_|$)/, '\1es\2'
inflect.plural /([aeiou])([A-Z]|_|$)([a-z]+)([rlnd])($)/, '\1s\2\3\4es\5'
inflect.plural /([rlnd])([A-Z]|_|$)([a-z]+)([aeiou])($)/, '\1es\2\3\4s\5'
inflect.singular /([aeiou])s([A-Z]|_|$)/, '\1\2'
inflect.singular /([rlnd])es([A-Z]|_|$)/, '\1\2'
inflect.singular /([aeiou])s([A-Z]|_)([a-z]+)([rlnd])es($)/, '\1\2\3\4\5'
inflect.singular /([rlnd])es([A-Z]|_)([a-z]+)([aeiou])s($)/, '\1\2\3\4\5'
@efrenfuentes
efrenfuentes / app.rb
Created November 15, 2012 18:03
Simple Sinatra Authentication
require 'rubygems'
require 'sinatra'
set :username,'Bond'
set :token,'shakenN0tstirr3d'
set :password,'007'
helpers do
def admin? ; request.cookies[settings.username] == settings.token ; end
def protected! ; halt [ 401, 'Not Authorized' ] unless admin? ; end
@efrenfuentes
efrenfuentes / login.rb
Created November 15, 2012 18:06 — forked from amscotti/login.rb
Sample of Sinatra authentication
require 'rubygems'
require 'bcrypt'
require 'haml'
require 'sinatra'
enable :sessions
userTable = {}
helpers do
#include <iostream>
using namespace std;
class Nodo
{
public:
Nodo(int numero, Nodo *siguiente = NULL)
{
this->numero = numero;
this->siguiente = siguiente;

Set up Django, nginx and uwsgi

Steps with explanations to set up a server using:

  • virtualenv
  • Django
  • nginx
  • uwsgi