Showing posts with label Blog. Show all posts
Showing posts with label Blog. Show all posts

Wednesday, May 14, 2008

Tried KDE4 on Kubuntu

I've been testing Kubuntu with KDE4 today and have learnt two lessons.

1) There's nothing to be eager about KDE4. I mean, seriously, the guys do a good job, but this is still the same good old kde3. Those plasma and dolphin stuffs, doesn't change much, that's like a good version of the superkaramba project, it looks nice but practically doesn't change the workflow at all. And as 99% of applications still from KDE3, if don't mention internal changes, in really you've got a new nice theme for kde.

I'm little bit disappointed, the fourth version was anounced for good couple of years ago and then been delayed several times and as the result we've got something pretty raw and almost nothing new.

Yup, that's it, there's nothing in really why you should migrate to kde4 so far.

2) The quality of kubuntu is lower then the quality of ubuntu. Sorry gus, but that's true. There are several things which works out of box in ubuntu, but doesn't work in kubuntu. Several things are left behind in order to keep the kde-purity, that left a bad feeling.

Friday, April 18, 2008

I think stories need chapters

This rspec's stories stuff is quite nice, I like it. But when I'm trying to write more or less complex story it turns out to a nightmare. It's quite hard to stay on the DRY way with the stories, you always need to repeat the stuffs again and again. Even if you organize your code in good and handy steps, you'll have to repeat them in the scenarios anyway.

So, I think it would be cool to have in the stories another level aka Chapter. Think even nested chapters. I could look like that.

Story "an item live-story" do
Chapter "items index" do
Given "two items"

Scenario "anonymous gets the index" do
Given "an anonymous user"
When "he GET /items"
Then "he should be redirected to the login_path"
end

Scenario "registered user gets the index" do
Given "a logged in user"
When "he GET /items"
Then "he should see the 'items/index' page"
And "both items should be on the page"
end

Then "something in common happens"
end
end

The idea is that the chapters were working like scopes for the inside subchapters and scenarios. You may specify there common givens and thens which will be applied to the internal parts. May be it could be useful to be able to attach additional steps for particular chapters.

Wednesday, April 16, 2008

Ajaxload - The Spinners Generator

Found today the resource ajaxload.info, you can generate your custom ajaxload spinners there.

The guys did pretty well I should say. There are lots of patterns, you can choose a transparent background and custom colors.

Nice stuff.

Tuesday, April 15, 2008

Displaying GIT Branch Name In Your Console

So, if you had been taken the gateway drug of GIT recently, then you probably feel the sake of branches and there's a little trick for you dear fellow.

Put (or change) the following stings in your ~/.bashrc file and you'll get a nice enhancement on your console prompt which will show your current git-branch when you're in a directory which is under git.

function git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1) /'
}

PS1='\[\033[0;37m\][\[\033[01;36m\]\W\[\033[0;37m\]] \[\033[0;32m\]$(git_branch)\[\033[00m\]\$ '

This is quite handy when you use the branches feature actively.

Sunday, April 6, 2008

Wish that thing in Ruby


class Array
def ||<<(i)
<< i unless include? i
end
end

Think, that would be logically appropriate, in similar to the ||= operation

Sunday, March 30, 2008

Idea about restful_authentication plugin

If you're using the restful_authentication plugin with your rails projects, there's a simple idea which might be interesting to you.

Idea as I said pretty simple. Rename the users_controller which the plugin generates to profiles_controller, and sequentially change the routes declaration

# from
map.resources :users
# to
map.resource :profile

The reason is simple as well. With the controller you actually manage the user's profile (the registration process for example), not the users collection in really. For administration purposes you may need more standard CRUD controller for the User unit later. And you will extend the existing controller, then you may run into some ugly constructions in it pretty soon.

But with such a simple renaming you'll keep the things more clear and reusable.

Tuesday, March 25, 2008

Another Work Is Done

With love and proud another piece of work been done and now on the air.

Met http://www.redstarpoker.com! Some pretty basic but loverly done rails work.

And don't blame me on the main menu with images, that's all the communists, they like such stuffs.

Monday, March 24, 2008

Creating element event handlers with RJS

If you're working with rails and ajax you probably familiar with the link_to_function helper. And especially with its ability to apply a block where you can put some RJS code. Sometimes it's pretty handy. Especially if you're not much javascript guru or just don't want to get dirty with it.

So, that's cool. But sometimes you might want to use RJS to write some events handling for say a form element. For example you've got a select box which switches different blocks on/off depends on what you choose and you need to wire the 'onchange' event with some logic. In a such case you can pass the :onchange value of the html_options argument in the 'select' helper method. The problem is that it applies a string, not a block where you can put in your RJS stuffs.

And the problem is solvable. There's another helper method which actually applies a block of rjs code and returns a string of compiled javascript code. It's name update_page. The link_to_function method calls it internally. For example you want to switch some blocks depend on a chosen language. This might look like that.

<%= select nil, nil, Language.to_options, {}, :onchange => update_page{ |page|
Language.all.each do |lang|
page << %{$("block-in-langage-#{lang.id}")[this.value == '#{lang.id}' ? 'show' : 'hide']();}
end
} %>

it's a little bit hacky, I've used this 'page << ' stuff and it's not probably a good rjs example. But I want to show the idea only. Whenever you need a javascript string and wish to write it in RJS, you can use the 'update_page' method and have it on.

Friday, March 21, 2008

How to define the pages-cache directory onfly

Generally, in Rails, when you have a deal with the page-cache feature, you define the cache output directory (if define at all) in the environment.rb, something like that

config.action_controller.page_cache_directory = RAILS_ROOT + "/public/cache/"

But sometimes you may need to add something special to the path on fly, when the controller is working. Say a language prefix or so. And you can do so in a nice one-line patch. You should overload the 'cache_page' method (not the 'caches_page' one), like that

def cache_page(content=nil, path=nil)
super content || response.body, path || (@language_name + request.path)
end

And you won't need to touch anything else, case all your controller caching settings will eventually call the method. Just notice, that the method should be public. And don't forget to add your hacky prefix to your sweepers.

That's pretty much it.

How to setup updated_at field manually

There's a simple case. Say I've got a model which logic depends on the magic updated_at field and I would like to test it. But the question is how to set the value manually up, when you need it? If you try something like

@article.update_attributes :updated_at => 10.minutes.ago

Then you'll have your updated_at field set to Time.now whatever you pass in it, because ActiveRecord will overwrite it by default.

The answer is simple, use the 'record_timestamps=' class-method which switches on/off the automatic updating of the created and updated fields.

Article.record_timestamps = false
@article.update_attributes :updated_at => 10.minutes.ago
Article.record_timestamps = true

That's it.

Wednesday, March 12, 2008

RSpec Dummyfication

When you're working with rspec and describing models relations you probably will need some dummy models, which wont bother you with all those validation stuffs. Yes, there's mock_model method, but the problem with it is that it stubs all the model methods first and the mocks don't have any relationships with the database.

And then if you need for your integration tests real models which will respond as real models and have database identification, you probably might find useful the following trick. Add the following strings into your spec_helper.rb file.

module Dummyficator
def dummy_inst(klass, attrs={ })
inst = klass.new attrs
inst.stub!(:valid?).and_return(true)
inst.save
inst
end
end

include Dummyficator

After this you'll be able to create dummy model instances in your specs like that

describe Group, "with users" do
before do
@group = dummy_inst Group
@group << dummy_inst User
@group << dummy_inst User, :username => 'dummy'
end

it "should have two users" do
@group.should have(2).users
end

it "should not destroy users" do
@group.destroy
User.find_by_username('dummy').should_not be_nil
end
end

This way you will be able to create new and new database records which will behave just as they should except the validation, so you can concentrate on the models relations not worrying about the models validation.

Sunday, March 2, 2008

TestCase 2.0-alpha is out

As I mentioned the TestCase project is going to be framework independent and now it is.

I've just released the version 2.0-alpha of the project. Functionally it's the same TestCase v 1.0, but the project had some major internal changes so now it runs on its own.

The project is designed such a way that it won't affect any framework stuffs, so you can safely use it with any of your projects. Use it with the lovely mootools or with jQuery if you wish so.

That's it, have fun.

Tuesday, February 19, 2008

Firefox 3 tries

Have installed FF 3-beta (Gecko/2008021416 Firefox/3.0b3), what can I say? Looks promising, they have revised many gui stuffs, now it looks quite nicer. And yes, as they had been promising, now it works with Cairo and renders native gtk widgets. That's cool.

But unfortunately, just as it was with FF 0.9 -> 1.0, FF 1.0 -> 1.5, FF 1.5 -> 2.0, all my plugins screwed up. No firebug, not firefox-webdevelop, etc. 8(

By itself FF 3, looks quite stable, had no problems so far, no crashes etc.

That's it. Will waiting.

Monday, February 18, 2008

Charged php-mode recharge

PHP is like a gangsta-rap. Everyone know that it's a bullshit, but from time to time do it for living.

So, as I had to support one of my customers with an old php-project recently, I've done some fixes in the charged php-mode. There are only minor fixes of highlighting issues, like the broken methods calls highlighting, $this_ calls lack, etc.

Get It Here

Thursday, February 14, 2008

discovery.com seems to have nice round hole in their security

I was trying to register on their forum and accidentally found myself logged in under another user.

How did I do so:

1) Hit the Login/Join button
2) Proceed to the registration form
3) Feel it as they wish to
4) Enter instead of the desired username a username of an existing user
5) Press submit.

That's it. I've received the confirmation email and found myself under the user which was registered several years ago and have some posts. I even managed to create a post and now having the discussion.

Tuesday, February 12, 2008

Epiphany updates look well

Have switched source tags from feisty to hardy on my laptop's ubuntu yesterday. And found that epiphany now, similar to knoqueror in kde, follows the gnome look'n'feel theme.





Looks quite nice. And note, it's on the gecko engine. Unfortunately Firefox, still renders the gray standard buttons.

Monday, February 11, 2008

Recursive Camelization

Felt myself not much well since wrote a non-recursive camelization example in the yesterday article. So, now I'm fixing the lack ;)


String.prototype._camelize = function() {
var _pos = this.lastIndexOf('_'), suffix = this.substr(_pos+1);
return _pos < 1 ? this : this.substr(0, _pos)._camelize()
+ suffix.charAt(0).toUpperCase() + suffix.substr(1);
};
alert('_camelize_me_pleaze'._camelize());


That's it.

Friday, February 8, 2008

TestCase is going to be a framework independent

Initially when I started TestCase I just needed some testing facility for my Prototype based code and I was not satisfied with the scriptaculous testing way. But now, it becomes obvious to me that the project is not uses Prototype much in really and I seems need to test some MooTools based code, and then some people are too excited about jQuery.

So, I've thought that it will good for us all to make the TestCase project framework independent and put all the frameworks related stuffs in plugins or something like that.

That's it. Watch out, TestCase 2.0 is on its way to every mind ;)

Thursday, February 7, 2008

Javish source code formatting for the php-mode

If you tried the php-mode on Emacs, you probably meet the situation that it follows the c-mode rules in the code formatting. And if then you're more OOP apologist you probably would prefer some more javish-looking source code. Good news is that you actually can get so. Emacs is a totally configurable thing.

Put the following code into your emacs config.

(defun my-phpstuff ()
(c-set-style "awk")
(c-set-offset 'arglist-close 0)
(c-set-offset 'string 'c-lineup-dont-change)
(c-set-offset 'arglist-cont-nonempty '+)
(c-set-offset 'case-label '+)
(c-set-offset 'comment-intro 0)
(c-set-offset 'defun-close 0)
(c-set-offset 'cpp-macro 0)
(c-set-offset 'knr-argdecl 'c-lineup-dont-change)

(setq tab-width 4
c-basic-offset 4
c-hanging-semi&comma-criteria nil
indent-tabs-mode nil
c-cleanup-list '(scope-operator)
c-comment-only-line-offset '(0 . 0)
c-backslash-column 48

c-hanging-colons-alist nil
c-hanging-comment-starter-p nil
c-hanging-comment-ender-p nil
c-indent-comments-syntactically-p nil
c-tab-always-indent t
c-comment-continuation-stars "* "
c-label-minimum-indentation 1
defun-prompt-regexp nil
)
)
(add-hook 'php-mode-hook 'my-phpstuff)


This will provide you a correct 4-spaces indentation for all of your constructions. If you prefer tabs instead of spaces, change indent-tabs-mode nil to indent-tabs-mode t and you'll have it.

Wednesday, February 6, 2008

Charged php-mode for Emacs and something more

Case the official maintainers of the php-mode seems to be busy people I public it here.

This is a charged php-mode for Emacs. I mean it's the freshest php-mode with some fixes/updates/improvements which I've written for myself and now I share with you.

It's based on the latest php-mode version 1.4.0-beta and contains all the original features and adds some new

1) Fixes in the code highlighting, especially in_the_underscored_functions
2) Added the php's built-in functions highlighting
3) Added the php-doc tags highlighting like @param @return, TODO, FIXME etc.
4) Added a hotkey and functionality to execute the current php-buffer with usual C-c C-c command
5) Added a hotkey and functionality to execute the current buffer with the phpunit util (C-c C-p C-u command)
6) Some another highlighting fixes/improvements

This is the screenshot (click to see the full version). Hope it's not too much beautiful to you ;)




Get it here

And as I mentioned there's more

There's another sweet stuff for php-editing which had to exists but somehow didn't. It's a php-electric mode. Similar to another -electric modes for emacs, it put some hot magic under your fingers and creates language constructions for you when you type.

Try, you will like it. It's simple but handy and have the following features

* autocompletion for the if/for/foreach etc blocks
* autocompletion for the classes/interfaces/functions
* autocompletion for paired symbols like [] () "" ''

You can get it here

Both files might be easily inserted into your system. Just put them where emacs can see them (say in ~/.emacs.d/) and insert into your emacs config couple of strings like that.

(require 'php-mode)
(require 'php-electric)


That's it have fun!