Welcome

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

What next?
1. Bookmark us with del.icio.us or Digg Us!
2. Subscribe to this site's RSS feed
3. Browse the site.
4. Post your own code snippets to the site!

newfolder contextual menu item with Automator

Right-click on a folder in a Finder window and select Automator -> newfolder to create a "NewFolder".


open -a Automator

#--------------------------------------------------

Drag or add actions here to build your workflow:
Library: Finder -> Action: Get Selected Finder Items
Library: Automator -> Action: Run Shell Script
                                 - Shell: /bin/sh
                                 - Pass input: as arguments

current_dir="$@"
name_of_new_dir="NewFolder"

if [[ -d "${current_dir}" ]] && [[ -w "${current_dir}" ]]; then
   /bin/mkdir -p "${current_dir}${name_of_new_dir}"
fi

exit 0


# now save the newfolder Automator workflow as a contextual menu item
Automator -> File -> Save As Plug-in ... -> Save Plug-in As: newfolder -> Plug-in for: Finder -> Save

#--------------------------------------------------

open ~/Library/Workflows/Applications/Finder/newfolder.workflow

# now open your Home directory, right-click on a folder and select Automator -> newfolder to create a "NewFolder" 
open ~

Dumb question i cant find answer to!!!

Hi Guys,

Sorry, i know this is probably a dumb question. I've been searching the net for hours and cant find an answer - I come close, but not exact.

I have very limited applescript knowledge, but all i want to do is make a script exactly the same as the finder's default 'make new folder in current/front window', however with a specific name that I want (instead of 'untitled folder')

Any help would be appreciated.

Kind Regards,

Jason
jjasonv@hotmail.com

tune2fs options

// my options for new EXT3 filesystem on second HDD

# tune2fs -O +dir_index,+large_file -o +journal_data_writeback /dev/sdb2

Log website response times with cURL in windows

This code snippet should be saved as a batch file and run in Windows. It can be set up as a scheduled task to log response times at a fixed interval. It takes one argument, the URL, which should be enclosed in quotes or Windows will barf on URLs with = (equals) signs in. If you don't supply any arguments, you will be prompted. Binary versions of curl are available via google.

If you have ISA:
REM measure response times for a site:
@echo off
IF a%1 == a (
  SET /P varHost=Enter the address, e.g. http://google.com: 
) ELSE (
  SET varHost=%1
)
SET startTime=%date% %time%
curl.exe --proxy-ntlm --proxy yourISAproxy:8080 --proxy-user username:password -s %varHost% > fulloutput.txt
echo %startTime%,%date% %time%,%varHost% >> respTimeLog.txt


If you have no proxy:
REM measure response times for a site:
@echo off
IF a%1 == a (
  SET /P varHost=Enter the address, e.g. http://google.com: 
) ELSE (
  SET varHost=%1
)
SET startTime=%date% %time%
curl -s %varHost% > fulloutput.txt
echo %startTime%,%date% %time%,%varHost% >> respTimeLog.txt

Run script just before linux reboot (runlevel 6 / rc6.d)

update-rc.d is the program (script) which creates the necessary symbolic links to the /etc/rcX.d directories.

Here we are running the script found at /etc/init.d/updatedb_start, within runlevel 6, which is reboot.

Running this will create a symbolic link to the actual script file which lives within /etc/init.d (as it always should).

So, within /etc/rc6.d/ we'll see a symbolic link to our script.

The period at the end of the command is required. Tells update-rc.d that we're finished with the command (no further runlevels to edit).

We're using "stop" instead of "start" because we want to run the script during the killing off scripts part of the rc6.d scripts.
This causes the script to be run with a "stop" parameter, for example: updatedb_start stop
We don't actually use the stop parameter in this case, it's just ignored.

update-rc.d updatedb_start stop 18 6 .

log to syslog

how to log something to syslog

logger This is my message to syslog

ActiveRecord reconnect to database

// my Merb consoles drop the db connection after the mysql timeout; I'd rather not reload the whole environment

ActiveRecord::Base.connection.reconnect!

trying to add trim_mode to BackDoor extension for RadiantCMS

// here's what I'm doing atm

<r:erb_tag name="langLink" >
<r:erb><%# url = <%= <r:expand tag="url" /> %><%= if (/\/en/.match(url))
url.sub(/\/([^\/]+)/,"/ja")
else
url.sub(/\/([^\/]+)/,"/en")
end %></r:erb></r:erb_tag>
<ul class="lang-links">
<li><r:if_url matches="^\/ja"><em>日本語</em></r:if_url><r:unless_url matches="^\/ja"><a href="<r:langLink></r:langLink>" title="<r:title /> in Japanese">日本語</a></r:unless_url></li>
<li><r:if_url matches="^\/en"><em>English</em></r:if_url><r:unless_url matches="^\/en"><a href="<r:langLink></r:langLink>" title="<r:title /> の英文ページ" class="last">Engish</a></r:unless_url></li>
</ul>


// but this gives me urls like this (note line break from if/else)

<li><a href="
/ja/" title="This page in Japanese">日本語</a></li>


// so let's hack BackDoor's erg tag

  tag "erb" do |tag|
    ERB.new( tag.expand).result( binding)
  end


// here's the documentation from erb.new

If trim_mode is passed a String containing one or more of the following modifiers, ERB will adjust its code generation as listed:

    %  enables Ruby code processing for lines beginning with %
    <> omit newline for lines starting with <% and ending in %>
    >  omit newline for lines ending in %>


// here's your new erb tag

  tag "er" do |tag|
    ERB.new(tag.expand, nil, true).result(binding)
  end


// but I'm not sure how to call it

<r:er trim_mode=">"> <!-- looks wack and doesn't work -->

No source code.

Remember you don't always need code in a formal language to express your idea.

Remember text.

Print a PDF file using the Acrobat Pro Javascript Console in OS X

// Print a PDF file using the Acrobat Javascript Console
// Press Command J to bring up the console in Acrobat
// After typing your code in the console, select it and press Control Enter to execute
// Uses current Page Setup when printing

var myDoc;

myDoc = app.openDoc("/Users/yourusername/Desktop/outputfolder/filename.pdf");
myDoc.print({bUI : false});
myDoc.closeDoc();