Download videos from any site with youtube-dl

Continuing on last week theme of downloading videos, youtube-dl is a nifty little utility that allows you to download videos to watch later, or for safekeeping.

Install with Homebrew:

You can now download videos from YouTube, BlipTV, Brightcove, Dailymotion, TED and many other supported sites:

That’s it for today.

Enjoy!

Setting up a wildcard DNS domain on Mac OS X

Setting up a wildcard DNS domain on Mac OS X

There are many ways to develop on a Mac, and many stack to choose from. One common and recurring need however is to access your local websites through a named domain, ie using example.dev. Thankfully, there is a really simple way to do this using Dnsmasq as a local resolver.

Install Dnsmasq

This is straightforward with Homebrew:

Configure Mac OS X

All we need to do is tell the resolver to use Dnsmasq for .dev domains:

 

You can now use any .dev domain and it will always resolve to 127.0.0.1:

 

Conclusion

This is very useful in particular for applications that use subdomains as account identifier: you can easily create new accounts on the fly, and never have to worry about your /etc/hosts file again.

Finally, you may also want to look at Pow (and powder). Pow will automatically start your Rails/Rack applications, and provides a port proxying feature for apps written in other languages. Definitely a great alternative.

That’s it for today.

Cheers!

fcrackzip example usage and Install fcrackzip on Mac OSX

About the App

Install the App

  1. Press Command+Space and type Terminal and press enter/return key.
  2. Run in Terminal app:
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
    and press enter/return key. Wait for the command to finish.
  3. Run:
    brew install fcrackzip

Done! You can now use fcrackzip.

Example

tuva  ~:  fcrackzip -l3 -u example.zip

PASSWORD FOUND!!!!: pw == a3ff

or

tuva  ~: fcrackzip -D -p password-list.txt -u example.zip

PHP strtotime() behavior using days of the week as frames of reference (Windows & Linux)

Say you want to get a set of timestamps so that you can query a database for all records that fall between the start of this week, and the end of this week.

One would logically try something like:


 

That will, in theory, give you a date range of Monday at 00:00:00, and Sunday at 23:59:59. Unforunately, that is not always the case.It turns out trying to find relative time references with strtotime is wonky. Depending on which day it currently is, and what day you’re trying to use as a frame of reference, you will get different results when using ‘this monday’ or ‘tuesday next week’ etc… The results are unintuitive, but more importantly, inconsistent in most cases.

Since strtotime() lets us do lazy math to get timestamps (e.g. ‘this monday – 1 week’), all we need to do is find some date string that works consistently 7 days of the week, and then we can reliably find other timestamps relative to that string. Any date string that does not have the same results for all 7 days, cannot be used as a frame of reference, as its value will change depending on what day it is!

From the tables below, we can see that the following three strings can be safely used as frames of reference in strtotime():


 

My suspicion is that certain strings consider Sunday to be the start of the week, while others consider Monday to be the start of the week, and probably round the time up or down in different ways.

Note that I have arbitrarily chosen Monday – March 4th, 2013 through Sunday – March 10th, 2013 as the week to test. Though given how wonky strtotime()’s behavior is, there’s a possibility that the behavior shown below varies from one week to the next! However, I did test various times throughout each day (e.g. 00:00:00 and 23:59:59) and thankfully the results were consistent.

So going back to our problem of getting timestamps for the start and end of this week, the cleanest and most reliable solution is this:

 

 

Using Monday as a frame of reference
If today = Mon, March 4th Tue, March 5th Wed, March 6th Thu, March 7th Fri, March 8th Sat, March 9th Sun, March 10th
strtotime(“this monday”) = March 4th March 11th March 11th March 11th March 11th March 11th March 11th
strtotime(“monday this week”) = March 4th March 4th March 4th March 4th March 4th March 4th March 11th
strtotime(“next monday”) = March 11th March 11th March 11th March 11th March 11th March 11th March 11th
strtotime(“monday next week”) = March 11th March 11th March 11th March 11th March 11th March 11th March 18th
strtotime(“last monday”) = February 25th March 4th March 4th March 4th March 4th March 4th March 4th
strtotime(“monday last week”) = February 25th February 25th February 25th February 25th February 25th February 25th March 4th
Using Tuesday as a frame of reference
If today = Mon, March 4th Tue, March 5th Wed, March 6th Thu, March 7th Fri, March 8th Sat, March 9th Sun, March 10th
strtotime(“this tuesday”) = March 5th March 5th March 12th March 12th March 12th March 12th March 12th
strtotime(“tuesday this week”) = March 5th March 5th March 5th March 5th March 5th March 5th March 12th
strtotime(“next tuesday”) = March 5th March 12th March 12th March 12th March 12th March 12th March 12th
strtotime(“tuesday next week”) = March 12th March 12th March 12th March 12th March 12th March 12th March 19th
strtotime(“last tuesday”) = February 26th February 26th March 5th March 5th March 5th March 5th March 5th
strtotime(“tuesday last week”) = February 26th February 26th February 26th February 26th February 26th February 26th March 5th
Using Wednesday as a frame of reference
If today = Mon, March 4th Tue, March 5th Wed, March 6th Thu, March 7th Fri, March 8th Sat, March 9th Sun, March 10th
strtotime(“this wednesday”) = March 6th March 6th March 6th March 13th March 13th March 13th March 13th
strtotime(“wednesday this week”) = March 6th March 6th March 6th March 6th March 6th March 6th March 13th
strtotime(“next wednesday”) = March 6th March 6th March 13th March 13th March 13th March 13th March 13th
strtotime(“wednesday next week”) = March 13th March 13th March 13th March 13th March 13th March 13th March 20th
strtotime(“last wednesday”) = February 27th February 27th February 27th March 6th March 6th March 6th March 6th
strtotime(“wednesday last week”) = February 27th February 27th February 27th February 27th February 27th February 27th March 6th
Using Thursday as a frame of reference
If today = Mon, March 4th Tue, March 5th Wed, March 6th Thu, March 7th Fri, March 8th Sat, March 9th Sun, March 10th
strtotime(“this thursday”) = March 7th March 7th March 7th March 7th March 14th March 14th March 14th
strtotime(“thursday this week”) = March 7th March 7th March 7th March 7th March 7th March 7th March 14th
strtotime(“next thursday”) = March 7th March 7th March 7th March 14th March 14th March 14th March 14th
strtotime(“thursday next week”) = March 14th March 14th March 14th March 14th March 14th March 14th March 21st
strtotime(“last thursday”) = February 28th February 28th February 28th February 28th March 7th March 7th March 7th
strtotime(“thursday last week”) = February 28th February 28th February 28th February 28th February 28th February 28th March 7th
Using Friday as a frame of reference
If today = Mon, March 4th Tue, March 5th Wed, March 6th Thu, March 7th Fri, March 8th Sat, March 9th Sun, March 10th
strtotime(“this friday”) = March 8th March 8th March 8th March 8th March 8th March 15th March 15th
strtotime(“friday this week”) = March 8th March 8th March 8th March 8th March 8th March 8th March 15th
strtotime(“next friday”) = March 8th March 8th March 8th March 8th March 15th March 15th March 15th
strtotime(“friday next week”) = March 15th March 15th March 15th March 15th March 15th March 15th March 22nd
strtotime(“last friday”) = March 1st March 1st March 1st March 1st March 1st March 8th March 8th
strtotime(“friday last week”) = March 1st March 1st March 1st March 1st March 1st March 1st March 8th
Using Saturday as a frame of reference
If today = Mon, March 4th Tue, March 5th Wed, March 6th Thu, March 7th Fri, March 8th Sat, March 9th Sun, March 10th
strtotime(“this saturday”) = March 9th March 9th March 9th March 9th March 9th March 9th March 16th
strtotime(“saturday this week”) = March 9th March 9th March 9th March 9th March 9th March 9th March 16th
strtotime(“next saturday”) = March 9th March 9th March 9th March 9th March 9th March 16th March 16th
strtotime(“saturday next week”) = March 16th March 16th March 16th March 16th March 16th March 16th March 23rd
strtotime(“last saturday”) = March 2nd March 2nd March 2nd March 2nd March 2nd March 2nd March 9th
strtotime(“saturday last week”) = March 2nd March 2nd March 2nd March 2nd March 2nd March 2nd March 9th
Using Sunday as a frame of reference
If today = Mon, March 4th Tue, March 5th Wed, March 6th Thu, March 7th Fri, March 8th Sat, March 9th Sun, March 10th
strtotime(“this sunday”) = March 10th March 10th March 10th March 10th March 10th March 10th March 10th
strtotime(“sunday this week”) = March 10th March 10th March 10th March 10th March 10th March 10th March 17th
strtotime(“next sunday”) = March 10th March 10th March 10th March 10th March 10th March 10th March 17th
strtotime(“sunday next week”) = March 17th March 17th March 17th March 17th March 17th March 17th March 24th
strtotime(“last sunday”) = March 3rd March 3rd March 3rd March 3rd March 3rd March 3rd March 3rd
strtotime(“sunday last week”) = March 3rd March 3rd March 3rd March 3rd March 3rd March 3rd March 10th

Sublime Text Personal Settings

Favorite Snippets

Close_windows_when_empty — Closes the whole window if there are only empty tabs open when you hit cmd + w.

 

Folder_exclude_patterns — Set up folder exclusion for commonly used directories in your projects.

Font_ — Set type preferences for readability. Obviously, a monospaced font like Source Code Pro from Adobe would be best.

Highlight_line — Highlights the currently selected line based on styles in your theme. Incredibly useful if you use multi-pane layouts.

Highlight_modified_tabs — Another theme-based preference, but still useful. If you have multiple tabs open, one with un-saved changes will be highlighted.

Match_ — On creation of an opening bracket/brace/etc, a closing one is inserted.

Scroll_ — Allows you to scroll past the end of a file, which is necessary, especially if you hate extra empty lines at the end of a file like I do. Scroll speed to 2 is also helpful if you’re impatient with large files.

Translate_tabs_to_spaces — Simple. Add this. And if you’re still using tabs in your code, quit it.

Complete Preferences:

 

Setting up Composer globally for Laravel 4

An easy way to set up composer globally is to follow the instructions on getcomposer.org site:

Now I can use composer by invoking just the composer command.

Optional way to do it, is to set up an alias:

and

MongoDB setup to Python

Respectively; Type the following command in the terminal to install MongoDB  🙂

 

Ubuntu – Numix GTK3 theme

Numix is a modern flat theme with a combination of light and dark elements. It supports Gnome, Unity, XFCE and Openbox.

Numix is a part of the Numix Project.

A request

If you have few bucks to spare, please consider purchasing the theme to support the project and show that you appreciate the work and time spent into making the theme.

As a bonus, you’ll also get an additional Numix Dark theme with the purchase.

Installation instructions

Ubuntu users can install Numix from our PPA using the following commands,

 

Arch Linux users can install Numix from the community repo

pacman -S numix-themes

Fedora and OpenSUSE users can install Numix from our build service repo.

 

Code and license

Report bugs or contribute at GitHub

License: GPL-3.0+

Extra Goodies

Numix Light GTK theme – fav.me/d6hds18

Wallpaper (Glimpse of the future) – fav.me/d6eqf86

Icons (Numix Circle) – fav.me/d6uxcka

Gnome Shell theme (Numix preset) – fav.me/d525x6c

KDE4 QtCurve style and Color scheme – fav.me/d71pch5

Ubuntu 14.04’e Linux, Apache, MySQL, PHP (LAMP) paketinin kurulması

LAMP Nedir?

LAMP terimini açmak gerekirse, Linux işletim sisteminde Apache Web Sunucusunun bulunması, Verilerin Mysql ile tutulması ve dinamik içeriğin PHP ile oluşturulmasıdır.

En büyük avantajlarından birisi bu dördünün de açık kaynak olmasıdır.

Bu anlatımdaki kurulum Ubuntu 14.04.1’de denenmiştir

Adım 1 – Apache Kurulumu

Apache dünyada en popüler web sunucudur. Ubuntu’nun paket yöneticisi olan apt ile kurulum yapacağımız için işimiz çok basit olacak.

Öncelikle paket veritabanını güncelleyelim

Apache2’yi kuralım

Kurulumdan sonra Apache2’nin çalışma durumunu öğrenmek için herhangi bir web tarayıcısından

adresini kullanabilirsiniz.

Adım 2 – MySQL Kurulumu

MySQL, bir veritabanı yönetim sistemidir.

Bu sefer MySQL’in yanında yardımcı(helper) paketler de kuracağız. Diğer paketlerle bağlantımızı sağlayacak.

Kurulum sırasında MySQL için şifre soracaktır.

Şimdi MySQL için biraz güvenlik önlemleri alalım. Eğer sadece geliştirme ortamı için kurulum yapıyorsanız aşağıdakileri incelemenize gerek yok diğer adıma geçebilirsiniz. Sadece production ortamı içindir.

MySQL sistem tablolarını oluşturtalım

Güvenlik amaçlı basit bir script çalıştıracağız. Girişleri olabildiğince kısıtlayacağız.

Script sırasında root şifresi isteyecektir. Kurulumda girdiğiniz şifreyi girin.

Remove anonymous users ? : Üye oluşturmaya gerek kalmadan giriş yapılmasını sağlar. Production ortamı için Yes diye cevaplayalım.

Disallow root login remotely ? : root kullanıcısının SADECE “localhost”‘dan giriş yapabilmesini sağlayacağız. Böylece root şifresi bilinse de sadece ana makineden giriş yapılabilir. Bu yüzden Yes diye cevaplayalım.

Remove test database and access to it ? : Varsayılan olarak MySQL, ‘test’ isminde bir veritabanı oluşturabilir ve herkesin erişebilmesini sağlar. Production ortamı için gereksiz olacaktır, bu yüzden Yes diye cevaplayalım.

Reload privilege tables now ? : İşlemlerin tam çalışması için yetki tablolarının güncellenmesi gerekiyor. Yes diye cevaplayalım.

Adım 3 – PHP Kurulumu

PHP, dinamik verilerin gösterimi, SQL veritabanlarından bilgilerinin alınması ve işlemlerin yönetilmesini sağlayacaktır.

PHP ile beraber helperları da yükleyelim

Apache, varsayılan olarak dizin arama işlemlerinde index.html index.cgi index.pl index.php index.xhtml index.htm dosyaları sırayla aranmaktadır. index.php‘yi biraz öne alacağız.

Bunun için dir.conf dosyasını düzenleyelim.

sudo nano /etc/apache2/mods-enabled/dir.conf index.html’den hemen sonra alabilirsiniz.

PHP’nin çalışması için Apache’nin yeniden başlatılması yani Apache’nin konfigürasyon dosyalarına tekrar bakması gerekiyor.

PHP Modüllerinin Kurulması

Yüklenebilir PHP5 Modülleri için şu şekilde arama yapabilirsiniz

Yükleyeceğiniz modülleri belirledikten sonra şöyle kurulum yapabilirsiniz

## Adım 4 – PHP’nin Test Edilmesi PHP‘yi test etmek için çok basit bir PHP kodu yazacağız.

BONUS – PHPMyAdmin Kurulumu

PHPMyAdmin’i kuralım

Web server olarak apache2‘yi seçin

dbconfig-common’un düzenleme yapmasına izin verin

MySQL ve PHPMyAdmin şifresini girin

Kurulum bittikten sonra Apache’ye PHPMyAdmin dosyasını ekleyeceğiz.

En alta Include ekleyeceğiz.

Apache’yi yeniden başlatalım

Kontrol amaçlı aşağıdaki adrese gidebilirsiniz

BONUS – Sanal Sunucu Oluşturma

Projelerinizde sürekli localhost/ kullanmak yerine projenize özel sanal sunucu oluşturabilirsiniz.

Örneğin AwesomeProject projeniz için

Çalışma Dizini: /var/www/awesomeproject/public_html

Log Dizini : /var/www/awesomeproject/logs

Site Adresi : http://awesomeproject/

Bu şekilde daha düzenli ve rahat olacaksınız.
Klasörlerin oluşturulması

Yetkilerin verilmesi

Örnek Sayfa Oluşturulması

Sanal sunucuyu test etmek için örnek bir sayfa oluşturacağız. Sanal sunucumuz içerisinde bir index.html dosyası oluşturalım.

İçerisine

Sanal Sunucu: projeadi
Sanal Sunucu Dosyasının Oluşturulması

Sanal sunucu dosyası oluşturalım.

İçerisine aşağıdakileri yapıştırabilirsiniz fakat projeadi yazdığım yerleri kendinize göre düzenleyin.

Dosyayı kaydedin ve kapatın.

Yeni sanal sunucunun çalışması için aktifleştirmemiz ve Apache’yi yeniden başlatmamız gerekiyor

GİT Kullanımı – Versiyon Kontrol Sistemleri

Git

Git ve Github kullanmak cok açıdan çok avantajlıdır. Bir deponun, ya da projenizin yaşadığı alan, tek bir merkezden yönetilmediği için aynı anda farklı kişiler aynı proje üstünde çalışabilir. Dünyada çok popüler olan Git, Github websitesi ile kullanılınca hem daha kolay hem de sosyalleşir. Aşağıdakı önemli terimleri anladığınız an Git felsefesinide kapmış olursunuz.

  • Depo/Repo: Kodlarınızın ve dosyalarınızın bulunduğu yer.
  • Commit: Kendi çalıştığınız katkı ya da gönderiyi repoya geri gönderirsiniz. Kim ne zaman ne değişiklikler yapmış onu görebilirsiniz.
  • Merge: İki farklı versiyonu birleştirmek.
  • Fork: Beğendiğiniz bir repoyu üstünde çalışmak için kendinize uyarmak.
  • Pull request: Üstünde çalıştığınız bir dosyayı commit ettikten sonra orijinal repoya geri eklemek isterseniz yapacağınız işlem.
  • Branch/dal: Bir projenin reposunu farklı bir şeye dönüştürmek isterseniz kendi branchinizi yaratabilirsiniz.

İyi commit nasıl yapılır?

  • Her bir değişikliği tek bir commite koyarsanız daha sonra geri almak istediğinizde tümden herşeyi geri almak zorunda kalmazsınız.
  • Her commit için açıklama zorunludur. Bir satır tam olarak ne değiştirdiğinizi yazarsanız ekibinizdeki öbür arkadaşlarınız kolaylıkla anlarlar. Mesela:

    git commit -m “bla.txt dosyasında buton rengini değiştirdim”

Komutlar

git init:

Bilgisayardaki bir dosyayı repo yaparsınız.

$ git clone URL

Olduğunuz dosyaya internette olan bir repoyu klonlarsınız.

$ git add bla.txt

bla.txt’i commit için eklemiş olursunuz

$ git commit -m “yorumlar”

bla.txt’i commit yapmış oluyorsunuz

git pull origin master

birleşmemiş değişiklikler varsa ilk önce onları merge eder

$ git push origin master

master branch’ine yaptığınız commit’i gönderirsiniz