up

programming

HTTP AUTH logout method

This code cause logout feeling for your user. The browser will ask again the username and password.

<?php
  header('WWW-Authenticate: Basic realm="protected area"');
  header('HTTP/1.0 401 Unauthorized');
?>

I use it with a logout controller, that set a session variable to true and redirect the request to the home page. And the home page check this session variable, and if it true, it sends these headers and set back the session variable to null.

Blog categories:  Web development

How to remove accidentally added files from git

I've read ti in stackoverflow:

E.g. to remove all *.gz files accidentally committed into git repository:

du -sh .git #==> e.g. 100M
git filter-branch --index-filter 'git rm --cached --ignore-unmatch *.gz' HEAD
git push origin master --force
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now
Blog categories:  Programming
Blog tags:  programming  git

PHP normalize function

I post my normalization function. This function find all illegal characters (like: Ő, Ű, ú, í, etc. ) and replace it to latin1 chars. (like: O, U, u, i, etc.) This function works for me on hungarian words. Try it on your text and post your comment about it.

Locomotive CMS

Today, I found a really good CMS. I'm looking for ruby 3 CMS for a while. I found this CMS solution that use my favorite NoSQL database system: MongoDB. I think multi site feature is rare in ror applications. Locomotive CMS do it.

Locomotive is an open source CMS for Rails 3. It's super flexible and integrates with Heroku and Amazon

Some features from technical Specs:

Blog categories:  Web development

Resolve Ruby on Rails UTF-8 error message: invalid multibyte char (US-ASCII)

I got the following error when i run a rake db:seed command on may RoR application:
invalid multibyte char (US-ASCII)

I found the soution and the error has gone away:
You should add a line to your file:

# encoding: utf-8

You can change the utf-8 to any other encoding that you use.
I added this line to my seeds.rb file and all UTF-8 code have been executed without errors.

My git branch operations and remote cheat sheet

Some useful git command with branches and remote repositories.

Remote operations

List remotes:

git remote -v

Add remote gitosis server:

git remote add <remote_name> git@myhostname.com:my_project_name.git
git push <remote_name> master

Where master is your branch name

Main git branch orperations

list branches:

git branch -v

-v is optional, you use it to get more verbose output

Create new branch:

git checkout -b <new_branch_name>
Blog categories:  Programming  Linux

Rails 3 Content Management Systems (CMS) - 2011

I've collected all open source CMS based on rails 3.x.

Rails CMS/Wiki/Forum

This is a very simple but feature rich CMS framework. It is good startpoint for a new rails project what will be wiki, Forum or CMS

Source: https://github.com/jlapier/Rails-CMS-Wiki-Forum

Casein CMS

This is a very minimal and lightweight CMS. Only users table created on rak db:migrate. It is a good start point for any content based application. This application scaffolding your rails app with a very beauty user interface.

how to install Ruby on rails webshop?

You have installed RoR3 and now you want to install a rails3 webshop.

I think the best solution is Spree. This is the only rails3 based e-commerce solution at this time.

How do you install this shop?

rails new rails3-shop
cd rails3-shop

edit Gemfile and add new line

gem 'spree'

Install new spree site.

rails g spree:site
rake spree:install
rake db:migrate
rake db:seed
rails server

The rails server command starts the webrick server. You should go to http://localhost:3000/ to check spree.

HTML number formatting with PHP

Here is my HTML number formatter. Sometimes the browsers wrap the numbers along thousand separator or decimal pont, but this function prevents this event.

function html_number_format($number, $decimals = 2, $dec_point = '.', $thousands_sep = ',') {
  if ($number === FALSE) {
    return '---';
  }
  return '<span style="white-space: nowrap;">'.number_format($number, $decimals, $dec_point, $thousands_sep).'</span>';
}