<![CDATA[Development Tips]> 2013-01-19T16:16:29+02:00 http://vigodome.com/ Octopress <![CDATA[Show free memory on OSX]> 2012-01-27T20:03:00+02:00 http://vigodome.com/blog/2012/01/27/show-free-memory-on-osx I was looking for Ubuntu’s free command for osx lion. I googled it as usual. I’ve seen that, there was a command called alloc and it is not available at the moment. I decided to write my own script in Ruby.

This is almost my first Ruby attempt! (I wrote in Python)

Based on “Activity Monitor.app” on OS X, used memory is a sum of:

  • Wired
  • Active
  • Inactive

memories. I managed to find out installed memory via sysctl -n hw.memsize. Here is the script that i wrote:

Gist is available here

free-memory.rb link
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env ruby
# encoding: utf-8

# By Uğur Özyılmazel, @vigobronx | @ugurozyilmazel
# http://vigodome.com | http://ugur.ozyilmazel.com | http://github.com/vigo

def get_paged_memory_usage(match_string, paging=4096)
  mvar = 3
  if match_string.split(/[^\w]/).length > 1
    mvar = 4
  end
  paged_val = `vm_stat | grep "Pages #{match_string}:" | awk '{ print $#{mvar}}'`.to_i
  gigabyte_val = (paged_val * paging) / 1024 / 1024 / 1000.0
end

installed_memory = `sysctl -n hw.memsize`.to_i / 1024 / 1024 / 1000.0
total_consumed = 0
['wired down', 'active', 'inactive'].each { |key| total_consumed += get_paged_memory_usage(key) }
printf("%.2fG", (installed_memory-total_consumed)) # returns in gigabytes

I embedded it to my prompt shell aka $PS1. I’ve checked and compared the results via htop and top commands. I get the same exac values. Due to OSX Lion, memory goes wild!!!. Especially Firefox leeches it abnormally. This little script kinda warns me that it is time to restart Firefox or close it for a while!

Update

Ain Tohvri mentioned my little tool here.

]>
<![CDATA[How to fix TM substitution]> 2012-01-14T15:10:00+02:00 http://vigodome.com/blog/2012/01/14/how-to-fix-tm-substitution I was adding some custom TM_ variables to TextMate. As you know, variable name always starts with TM_ letters. I had some funny moments but i figured it out (I mean remembered).

To fix this, you must un-check TM option at System Preferences > Language & Text

]>
<![CDATA[Changing TextMate's comment out behavior for CSS scope]> 2012-01-12T10:28:00+02:00 http://vigodome.com/blog/2012/01/12/changing-textmates-comment-out-behavior Block commenting is very annoying most of the times while writing CSS. It is not working like the other scopes (Python, JavaScript).

As you know, when you comment out a block in CSS it looks like this:

Block commented out CSS Snippet 1
1
2
3
4
5
/*.test {
    border: 1px solid #000;
    color: #f0f;
    margin: 0;
}*/

Pain starts when you want to undo or comment/un-comment quickly. You need to select precisely and need to fix lines and breaks. It is not easy as Python or JavaScript.

I would be better, if i can turn block commenting to this:

Block commented out CSS Snippet 2
1
2
3
4
5
/*.test {*/
/*    border: 1px solid #000;*/
/*    color: #f0f;*/
/*    margin: 0;*/
/*}*/

Open Bundles > Bundle Editor and choose CSS > Comments and add these lines:

{   name = 'TM_COMMENT_MODE';
    value = 'line';
},

TextMate Bundle Editor

Now it turns to this (8

]>
<![CDATA[Change default shell, use new Bash which is installed from Homebrew]> 2011-12-30T11:52:00+02:00 http://vigodome.com/blog/2011/12/30/change-default-shell Do to lack of Associative Arrays in Bash (Version < 3) i decided to install bash from Homebrew.

brew install bash

After installation, you must set your new bash as default bash in to your system. Homebrew installs bash to

/usr/local/bin/

If you wish to check your current bash version, just echo these variables:

echo $BASH_VERSION # gives full version
echo $BASH_VERSINFO # gives major version number

We will use chsh command to proceed but before that, we must add this new bash location in to /etc/shells. Otherwise, system will alert an error. Now, lets edit file:

sudo nano /etc/shells

add this line at the end of the list:

/usr/local/bin/bash

Now, we can run chsh command:

chsh -s /usr/local/bin/bash YOUR_USER_NAME

Enter your password to proceed. Now you can restart Terminal.app and check if the installation is correct:

echo $BASH_VERSION

Now you can define:

Associative Array Declaration requires BASH version 4 or higher
1
declare -A MY_ARRAY
]>
<![CDATA[Show categories and post count in Octopress]> 2011-12-22T11:17:00+02:00 http://vigodome.com/blog/2011/12/22/show-categories-and-post-count-in-octopress Wouldn’t it be great to have Categories page in Octopress? If so, create a new page for Categories:

New Octopress page
1
rake new_page[blog/categories]

Open blog/categories/index.markdown and insert this snippet:

Categories
1
2
3
4
5
<ul>
{% for item in site.categories %}
    <li><a href="/blog/categories/{{ item[0] }}/">{{ item[0] | capitalize }}</a> [ {{ item[1].size }} ]</li>
{% endfor %}
</ul>

If you like to see the result, check out my Categories page.

For the record, thanks to Jim Pravetz for the Liquid Syntax tip.

]>
<![CDATA[TextMate : Show files beginning with dot]> 2011-12-22T10:14:00+02:00 http://vigodome.com/blog/2011/12/22/textmate-show-files-beginning-with-dot I was checking some files related to Sinatra yesterday and noticed that TextMate is not showing files which are started with . character. Like .autotest .rspec. After a quick googling, found Wil Linssen’s web site.

Just go to >

Preferences > Advanced > Folder References and change the pattern to:

!(/\.(?!.)[^/]*|\.(tmproj|o|pyc)|/Icon\r|/svn-commit(\.[2-9])?\.tmp)$

After making this, I noticed that, .DS_Store files are shown too! I did a quick fix to this, just changed to:

!(/\.(?!.)[^/]*|\.(tmproj|o|pyc|DS_Store)|/Icon\r|/svn-commit(\.[2-9])?\.tmp)$

TextMate screenshot

]>
<![CDATA[Hello World]> 2011-12-18T17:54:00+02:00 http://vigodome.com/blog/2011/12/18/hello-world Normally I blog in Turkish, which is my native language. From now on, I’ll try to keep it simple and post as much as I can about my development interests in English with this lovely blogging engine called: Octopress.

I’m a Python / Django developer. I’m building web application. I’ve seen many tweets about Octopress, especially developers was telling that how Octopress is flexible for posting code examples and snippets.

Yes It is true!

It is insanely true that Octopress is a great and simple blogging engine for developers. Its written in Ruby. If you are familiar to the Ruby world like Sinata, Jekyll, Sass, Yaml everthing will be easier than.

Don’t worry, you really don’t need to know any of those terms. Just read and follow the steps which is mentioned in the Octopress Docs.

I just did few tweaks to customize my own website. Also, i rapidly created a TextMate bundle too. Check out Octopress TextMate Bundle.

My Version of Octopress

I’ve added another layout called: plain. Normally, you need to:

Create New Page
1
rake new_page[filename]

Right now, if you pass second parameter, which is is_plane_page, creates plain page layout.

Create New Plain Page
1
rake new_page[filename,true]

This creates:

Plain Page Layout
1
2
3
4
5
6
7
8
9
---
layout: plain
title: "[page title]"
comments: false
sharing: false
footer: false
author:
asides: [asides/recent_posts.html, asides/twitter.html, asides/github.html]
---

I’ve just duplicated the file source/_layouts/page.html and created plain.html:

My Custom Layout html (octopress-layout-plain.html) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
---
layout: default
---

<div>
<article role="article">
  {% if page.title %}
  <header>
    <h1 class="entry-title">{% if site.titlecase %}{{ page.title | titlecase }}{% else %}{{ page.title }}{% endif %}</h1>
    {% if page.date %}<p class="meta">{% include post/date.html %}{{ time }}</p>{% endif %}
  </header>
  {% endif %}
  {{ content }}
  {% unless page.footer == false %}
    <footer>
      {% if page.date or page.author %}<p class="meta">
        {% if page.author %}{% include post/author.html %}{% endif %}
        {% include post/date.html %}{% if updated %}{{ updated }}{% else %}{{ time }}{% endif %}
        {% if page.categories %}{% include post/categories.html %}{% endif %}
      </p>{% endif %}
      {% unless page.sharing == false %}
        {% include post/sharing.html %}
      {% endunless %}
    </footer>
  {% endunless %}
</article>
{% if site.disqus_short_name and page.comments == true %}
  <section>
    <h1>Comments</h1>
    <div id="disqus_thread" aria-live="polite">{% include post/disqus_thread.html %}</div>
  </section>
{% endif %}
</div>
{% unless page.sidebar == false %}
    {% unless page.asides == false %}
    <aside class="sidebar">
        {% include_array asides %}
    </aside>
    {% endunless %}
{% endunless %}

If you check line 35, you’ll see the page.asides variable. My plain page layout allows you to add page based asides. Now you can change asides in every page you like to.

Here is my Rakefile tweak, just did this small change:

My Custom Rakefile diff (octopress-layout-plain-Rakefile.diff) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
--- Rakefile    2011-12-21 23:35:10.000000000 +0200
+++ Rakefile-mine    2011-12-21 23:34:18.000000000 +0200
@@ -1,8 +1,9 @@
 # usage rake new_page[my-new-page] or rake new_page[my-new-page.html] or rake new_page (defaults to "new-page.markdown")
-desc "Create a new page in #{source_dir}/(filename)/index.#{new_page_ext}"
-task :new_page, :filename do |t, args|
+desc "Create a new page (or plain page) in #{source_dir}/(filename)/index.#{new_page_ext}"
+task :new_page, :filename, :is_plane_page do |t, args|
   raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
   args.with_defaults(:filename => 'new-page')
+  args.with_defaults(:is_plane_page => '')
   page_dir = [source_dir]
   if args.filename.downcase =~ /(^.+/)?(.+)/
     filename, dot, extension = $2.rpartition('.').reject(&:empty?)         # Get filename and extension
@@ -24,12 +25,22 @@
     puts "Creating new page: #{file}"
     open(file, 'w') do |page|
       page.puts "---"
-      page.puts "layout: page"
-      page.puts "title: \"#{title}\""
-      page.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M')}"
-      page.puts "comments: true"
-      page.puts "sharing: true"
-      page.puts "footer: true"
+      if args.is_plane_page.length > 0
+        page.puts "layout: plain"
+        page.puts "title: \"#{title}\""
+        page.puts "comments: false"
+        page.puts "sharing: false"
+        page.puts "footer: false"
+        page.puts "sidebar:"
+        page.puts "asides:"
+      else
+        page.puts "layout: page"
+        page.puts "title: \"#{title}\""
+        page.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M')}"
+        page.puts "comments: true"
+        page.puts "sharing: true"
+        page.puts "footer: true"
+      end
       page.puts "---"
     end
   else

Well, my next plan is to find out how to add language/locale support for date object. Month names, day names and all the other string based things are need to be customizable via _config.yml (I belive)

]>