Keypress vs keydown in jquery

In todays web world, forms and input bars are very important. We all use searching and filtering in our applications. The easiest and obvious way to do this while using JS(jquery) is binding key events to the search bar.

The event I usually bound was ‘keypress’. This is fine and works good. But the actual meaning of keypress , in its original form in IE world (!!!!!) is the event which actually adds some value in the input field. Some keys like backspace, delete, clt etc do not add any value and hence are not detected by keypress event.

These are important keys as often in filtering when the input field is empty, we might want to show all results. The user might type some query and delete it and hence detection of such keys is important.

To avoid such confusion, one should always use keydown or keyup events. These events detect events where any key is pressed and one can use e.which to determine what key is pressed and perform action.

 

I personally like keyup becuase keydown event is called just after pressing the key and hence value of input field lags one character behind the actual input.

 

Hope it helps !

WiFi issues on Ubuntu 12.04

Hey ,

Recently installed ubuntu 12.04 on a fresh and clean system. While it works like a charm, a very irritating issue was that the inbuilt wireless card was not working. The ethernet connection using wire worked fine. Googled a lot and wasnt able to figure things out. Finally, backports saved my day. Here is the procedure I followed incase someone finds it useful.

 

Installing backports:

sudo apt-get install  linux-backports-modules-cw-3.8-precise-generic 

Some generic headers and libraries:

sudo apt-get install linux-headers-generic build-essential

Download this file and extract it at a location of your choice.
Navigate to the extracted directory using terminal and try:

make defconfig-ath9k
make
sudo make install

Reboot the system and ideally wireless should work!

Hope it helps.

Guake – Annoying feature of renaming tabs

I am a huge fan of guake terminal and after having used it for quite a while, I am literally addicted to it.

Recently, I encountered a very annoying feature which is when I rename a tab and perform any operation on that tab, the name I gave disappears and the absolute path is shown.

This was very painful because I am used to work with multiple tabs open and naming helps navigation.

After some googling, I found a solution which I present below.

Install gconf-editor.

sudo apt-get install gconf-editor

Start gcong-editor

gconf-editor

Browse to apps/general/guake/general.

On the right hand side, uncheck the “use_vte_titles” item and close it and restart guake.

All tabs would be named “Terminal” and renaming would preserve it.

The technical reason for doing this is the following piece of code:

def on_terminal_title_changed(self, vte, box):
    use_them = self.client.get_bool(KEY("/general/use_vte_titles"))
    if not use_them:
        return
    page = self.notebook.page_num(box)
    self.tabs.get_children()[page].set_label(vte.get_window_title())

As we can see ‘use_vte_titles' key prevents the autorenaming feature

Hope this helps and enjoy using guake.

Changing the text color of your Icons on Desktop in Ubuntu

Recently. I encountered a weird requirement.

I had changes my background image to a white colored image due to which the text on the icons was not visible.

Thus I wanted to change the text color of the icons on Desktop to black.

It turns out that is fairly simple.

Here are the steps :

Go to

 /usr/share/themes/Radiance/gtk-3.0/apps/

NOTE: I use the radiance theme and hence this path. In case you are using a different theme, replace “Radiance” with your theme name.

Here open a file called as “nautilus.css” in a simple text editor.

Somewhere near line 8-10 , there is a desktop mode where you can make your changes.

Find the line

color:@bg_color

Instead of removing it, comment this out and below that, copy the same line and use the hex code of the color you want to use.

For example, in my case it looks like:

color:#000000

Not a big deal but hope it helps !!

PreProcessing in Paperclip

Hi.

If at all you want to do any kind of prepreocessing on attachments using paperclip then here is a simple(not wen i did it for the first time…) way of getting a TempFile object and doing whatever you want.

Here I set the size of image (actually reduce the original size into half)

 

class Passet < ActiveRecord::Base
attr_accessible :caption, :markup, :media_passet, :pcontent_id
has_attached_file :media_passet,
:styles => {

: original => {
:geometry => Proc.new { |instance| instance.set_size },
:quality => 10
}
}

belongs_to :pcontent

def set_size

ori_img =Paperclip::Geometry.from_file(self.media_passet.queued_for_write[:original].path)

“#{ori_img.width/2}x#{ori_img.height/2}”

end
end

Here I reduce the dimensions if the image and reduce the quality too.

This way, I can save a 1.1MB image as 39.2KB image,

It it what I required,and I hope this will give you a hint about your own application.

 

Hope it helps.

PS: there are many other(mayb elegant solutions) which can be found on paperclip github page whose link I have posted above.