Bundle Config & Bundle Open

I wanted to be able to open up gems easily from the command line. I tried `bundle open unicorn` and got the following error:

To open a bundled gem, set $EDITOR or $BUNDLER_EDITOR

To get rid of this error I used `export BUNDLER_EDITOR=mate`. This causes TextMate to open the gem of choice when I call `bundle open unicorn`

Continue Reading…

Posted by Liah on Feb 25, 2011

Escaping and Unescaping in HAML

To turn escaped HTML into HAML, use != instead of just =
To escape unescaped HTML, use &= instead of just =.

> Haml::Engine.new('!= "

Hello World

"').render
=> "

Hello World

\n"
> Haml::Engine.new('%p Hello World').render
=> "

Hello World

\n"
> Haml::Engine.new('= "

Hello World

"').render
=> "

Hello World

\n"


Resources

Unescaping HTML
Escaping HTML Continue Reading…

Posted by Liah on Feb 04, 2011

redirect_to vs render

  • redirect_to causes the browser to receive a 302.
  • The browser makes a brand new request and you will need to supply the browser with the information it needs to make the request such as the object attributes.
  • Any existing variables will be lost.
  • redirect_to is the right choice when you are posting a completely filled out form with valid data.
  • render causes the browser to return a 200.
  • The browser does not make a new request and instead just renders the page you specify without sending any information to it.
  • The code in the rendered action will not be executed, it simply returns the view
  • render is the right choice when a form was incorrectly filled out and you want to display errors on the page you were just on as well as saving state of all the data that had already been entered into the form.

A link that helped me:
http://www.helloworlder.com/?p=6 Continue Reading…

Posted by Liah on Feb 02, 2011

Remove Files Older Than a Particular Date From a Directory in Unix

I have a folder filled with hundreds of images. Most of the images were first added to the folder on May 19th. The folder I'm moving them to already has all the images that were added on May 19th, so to save time, I don't want to move the May 19th images. I made a back up of my images folder that and am using the below commands within it. I only want to keep images added after May 19th in the folder so that I can zip them up and move them to another server. I'm using a dummy folder I made locally to test this out. Here are the unix commands I will use:


[Liah-Hansens-MacBook-Pro:~/test]$ ls -al
total 0
drwxr-xr-x 6 liahhansen staff 204 Dec 15 15:01 ./
drwxr-xr-x+ 75 liahhansen staff 2550 Dec 14 19:18 ../
-rw-r--r-- 1 liahhansen staff 0 Dec 15 13:58 goodbye
drwxr-xr-x 2 liahhansen staff 68 Dec 14 19:30 happy/
-rw-r--r-- 1 liahhansen staff 0 Dec 15 13:58 hello
-rw-r--r-- 1 liahhansen staff 0 May 24 2010 timefilealittleolder

[Liah-Hansens-MacBook-Pro:~/test]$ touch -am 05192010 timefile

[Liah-Hansens-MacBook-Pro:~/xargs_test]$ ls -al
total 0
drwxr-xr-x 7 liahhansen staff 238 Dec 15 15:11 ./
drwxr-xr-x+ 75 liahhansen staff 2550 Dec 14 19:18 ../
-rw-r--r-- 1 liahhansen staff 0 Dec 15 13:58 goodbye
drwxr-xr-x 2 liahhansen staff 68 Dec 14 19:30 happy/
-rw-r--r-- 1 liahhansen staff 0 Dec 15 13:58 hello
-rw-r--r-- 1 liahhansen staff 0 May 19 2010 timefile
-rw-r--r-- 1 liahhansen staff 0 May 24 2010 timefilealittleolder

The important part:

[Liah-Hansens-MacBook-Pro:~/test]$ find . -mtime +208 -type f | xargs rm

[Liah-Hansens-MacBook-Pro:~/xargs_test]$ ls -al
total 0
drwxr-xr-x 6 liahhansen staff 204 Dec 15 15:11 ./
drwxr-xr-x+ 75 liahhansen staff 2550 Dec 14 19:18 ../
-rw-r--r-- 1 liahhansen staff 0 Dec 15 13:58 goodbye
drwxr-xr-x 2 liahhansen staff 68 Dec 14 19:30 happy/
-rw-r--r-- 1 liahhansen staff 0 Dec 15 13:58 hello
-rw-r--r-- 1 liahhansen staff 0 May 24 2010 timefilealittleolder

Now timefile is gone. Yay!

When I performed these commands on the real files, I ran into a problem where many of the file names had whitespace in them. This caused rm to fail and I still had many files left in the folder from May 19th. Here is the command that got rid of them once and for all:

find . -mtime +208 -type f | xargs -I{} rm '{}'

Checking just to make sure:
ls -al |grep "May 19" | wc -l
0

Golden!

Continue Reading…

Posted by Liah on Dec 15, 2010

First Program in C

Now that I’ve got Ruby and Rails fairly well learned and practiced, I decided it was time to start working towards my long term goal of blending my programming skills with my love of art. Here is my first baby step towards learning C:

touch foo.c

mate foo.c

In foo.c I wrote (with the help of my roommate Sean):

`#include <stdio.h> int main() {

int i;
printf("Hello World!!!!!!\n");
for(i=0; i<5; i++) {
    printf("%d\n", i);
}
return 0;

}`

Next, I compiled my program:

gcc foo.c

This created a file called a.out

Next I ran a.out

./a.out

And it out put:

Hello World!!!!!! 0 1 2 3 4

Sean also taught me how to define the name of the out file:

gcc -o foo foo.c

This let me do the following to execute my program:

./foo

Continue Reading…

Posted by Liah on Oct 04, 2010