Skip to content

Instantly share code, notes, and snippets.

View sofadesign's full-sized avatar

Fabrice Luraine sofadesign

  • http://www.lunaweb.fr
View GitHub Profile
# mysql-python + snow leopard + mysql build with macports #
# Because on Snow Leopard macports installs the 64bits version of Mysql Server,
# you can't simply make a `python easy_install mysql-python`
# So we need to download sources and build it with correct flags. After fetching sources [MySQL-python-1.2.3c1](http://sourceforge.net/projects/mysql-python/):
tar xzf MySQL-python-1.2.3c1.tar.gz
cd MySQL-python-1.2.3c1
<?php
function before($route)
{
# Authentication if required
$uri = request_uri();
$is_admin = preg_match('%^/admin(/.+)?$%', $uri);
$auth_required = $is_admin && $uri != "/admin/login" && $uri != "/admin/logout";
if($auth_required) authentication_is_required();
<?php
function autoload_controller($callback)
{
$path = option('controllers_dir');
if(strpos($callback, 'admin_') === 0)
{
$path = file_path($path, 'admin');
}
require_once_dir($path);
# Ways to execute a shell script in Ruby
# Example Script - Joseph Pecoraro
cmd = "echo 'hi'" # Sample string that can be used
# 1. Kernel#` - commonly called backticks - `cmd`
# This is like many other languages, including bash, PHP, and Perl
# Returns the result of the shell command
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111
DROP TABLE IF EXISTS `scores`;
CREATE TABLE `scores` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`value` char(1) DEFAULT NULL,
`level` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
LOCK TABLES `scores` WRITE;
// 1.
function foo(){
function bar() {return 3;}
return bar();
function bar() {return 8;}
}
alert(foo()); // 8
// mais
// 2.
#
# smart_label_form_builder.rb
#
# original code from:
# http://openmonkey.com/articles/2010/03/rails-labels-with-blocks
#
# --
# adding HAML compatibility (fabrice AT sofa-design DOT net)
#
class SmartLabelFormBuilder < ActionView::Helpers::FormBuilder
#!/usr/bin/ruby
SIX (UNIMPRESSIVE) # Markdown version:
REASONS CAMPING IS BETTER # 1) Download this email
THAN YOU WOULD IMAGINE # 2) ruby email.rb
reasons.push(COMMUNITY) do %%
Yes, Sinatra has a big community, but Camping definitely has a great
community too. Size doesn't always matter. Because there are so few users,
it means every single issue gets full attention.
@sofadesign
sofadesign / nginx.conf
Created November 25, 2010 14:17 — forked from mikhailov/installation.sh
Nginx+passenger application config: ssl redirection, http headers, passenger optimal settings. see details: http://mikhailov.posterous.com/nginx
user app;
worker_processes 2;
error_log /home/app/logs/nginx.error.log info;
events {
worker_connections 1024;
}
@sofadesign
sofadesign / rails-hhtp-headers.rb
Created January 22, 2011 15:47
des Headers HTTP personnalisés dans Rails
# des Headers HTTP personnalisés dans Rails:
class MyController
before_filter :custom_response_headers
def custom_response_headers
response.headers["X-Luna-Mood"] = ";-)"
# …
end
end