There is nothing more powerful than an idea.

Except for an idea put into action.

27 April 2012 1 Comment

Simple javascript string substitution method

My simple and powerful string substitution method like python’s %s and django’s template language.

var mystring = "Hello {{ name }} {{ surname }}";

mystring.render({
  "name": "John",
  "surname": "Doe",
});
// "Hello John Doe"

To use this method add underscore.js and this short code:

String.prototype.render = function(obj) {
  return _.reduce(_.keys(obj),function(t,k){return t.replace(new RegExp("\{\{(\ *)"+k+"(\ *)\}\}","g"),obj[k])},this.toString());
};

You don’t need to use ugly string concatenation anymore :)

Tags:
12 October 2011 4 Comments

Ubuntu 11.10 Oneiric Ocelot Gedit 3 Indent Lines Plugin

Here is the “Indent Lines Plugin” that I wrote for gedit3:

https://bitbucket.org/serdarakarca/gedit3-plugins

 

How to use

  • Extract files and move into ~/.local/share/gedit/plugins or /usr/lib/gedit/plugins/
  • Activate plugin from Edit > Preferences > Plugins > Indent Lines
  • Try Ctrl+t and Ctrl+Shift+t
21 May 2010 17 Comments

Lucid Lynx and Gedit “Indent Lines” Plugin

My favourite text editor is gedit. I use gedit because it’s light and very powerful. Unfortunately by lucid upgrade, the indent feature has been removed. Maybe developers thought that tab was enough to indent lines but it is not. So, I want my “Indent Lines” plugin again. And if you want your indent feature back, here is the plugin:

64 bit:
http://yuix.org/wp-content/uploads/2010/05/indent_lines.zip

22 March 2010 1 Comment

Native Multiple File Upload Support by Firefox 3.6

I fed up with Flash Uploaders like Uplodify, YUI Uploader etc. Because any of them works… It doesn’t work and you can’t debug it. Flash plugin is absolutely very painful thing.

At the end, by Firefox 3.6 native multiple file upload suppport has came. I implemented it at Markafoni.com admin panel. Here is an example:

We use Django at backend. Here is Django code to get files:

images = request.FILES.getlist("file[]")
for i in images:
    filename = i.name
    raw_data = i.read()
    ... write raw_data to path/filename ...

If you like php:

foreach ($_FILES['file']['name'] as $filename) {
    echo $filename;
    ... maybe you want to move it anywhere ...
}
18 March 2010 0 Comments

Can’t decide to doctype? It’s easy!

If you think doctype declerations are very long and ugly just use html5 doctype.

<!doctype html>

When I saw this doctype I thought IE would switch to quirks mode. Surprisingly, all major browsers switch to standarts mode with Html5 doctype. All you need is <!doctype html>

12 November 2009 0 Comments

YUI’ye Baslangic: YUI Nasil Kullanilir?


YUI, YAHOO tarafından geliştirilen içerisinde javascript ve css kodları bulunduran gelişmiş bir arayüz kütüphanesidir. Arayüz geliştiricilerinin tüm ihtiyaçlarını karşılayacak kadar zengindir. YUI’nin nasıl kullanıldığını adım adım öğreneceğiz.

Devamını okumak için lütfen tıklayınız…

[...]

10 November 2009 0 Comments

Ubuntu 9.10 ve Vodafone 3G Modem: Huawei E620

3G modemi ilk kez Ubuntu 9.04 te denemiştim ve sonuç mükemmeldi. Hiç bir driver yüklemeden, ilk denemede internete bağlanabilmiştim. Biricik işletim sistemim Ubuntu’ya olan hayranlığım bir kat daha artmıştı. Fakat 9.10′la birlikte ben gibi bir çok Ubuntu kullanıcısı hayal kırıklığına uğradı. 9.10 da 3G modemler USB bellek olarak görünüyor. Modem olarak sisteme bağlanmadığı için internete girmek de mümkün olmuyor. Böylece Microsoft’un Windows işletim sistemleri için hazırlanmış olan bu `kendi driverını yanında taşıyan modem` modeli Ubuntu’nun yoluna taş koymuş oldu.

Yine de Unix’te çareler tükenmez. Aşağıdaki kodları sırayla çalıştırarak Ubuntu 9.10′da da modeminizi internete hazır duruma getirebilirsiniz. Fakat bu kodu çalıştırmadan önce Usb Bellek olarak sisteme bağlanan modemi ‘Safely remove’ etmemiz gerekiyor. Kodları çalıştırdıktan sonra 3G bağlantımız Network Manager’da listelenecektir. Ubuntu takımı bu hatayı düzeltene kadar malesef her açılışta bu hatayı elle düzeltmemiz gerekiyor.

sudo rmmod usb-storage
sudo modprobe -r option
sudo modprobe -r usbserial
sudo modprobe usbserial vendor=0x12d1 product=0x1001
sudo pppd ttyUSB0
10 November 2009 0 Comments

IE7 Bug: On window resize relative positioned elements disappear

If you have relative positioned or floating elements on your page, try to resize your page in IE7, you will see some elements disappear. I also know that sometimes hovering block displayed anchors causes this bug.

Problem is causeing from haslayout property of these elements. If we change haslayout property, the problem is going to be solved. An easy hack of haslayout property is applying “zoom:1″ to elements:

relative_elements_selector {
  zoom:1;
}
9 November 2009 0 Comments

YUI Selector IE8 Bug and Solution

We used YUI 2.5.2 version for a long time on markafoni.com. With the new face of markafoni I decided to update YUI version. I updated YUI to 2.8rc version, but surprisingly I saw javascript errors in all IE8 pages. After googling I found the solution. The problem is was here in selector.js (or selector-min.js):

if(YAHOO.env.ua.ie && YAHOO.env.ua.ie<8)

Change to:

if(YAHOO.env.ua.ie && ((!document.documentMode && YAHOO.env.ua.ie<8) || document.documentMode < 8))
5 November 2009 1 Comment

Thinkpad SL500 Ubuntu Drivers

I recently bought a new Thinkpad SL500. I installed a fresh Ubuntu 9.10. Unfortunately media keys and bluetooth was not working. After googling I found an experimental driver for media keys and bluetooth.

Here is the solution; first download driver from http://github.com/tetromino/lenovo-sl-laptop

After unpacking it. Run commands in the folder:

make all
sudo cp lenovo-sl-laptop.ko /lib/modules/`uname -r`/kernel/drivers/misc
sudo depmod
sudo modprobe lenovo-sl-laptop