Scripting

Ramblings and links to interesting snippets


Clockwork for Laravel

unnamed

While watching some tutorials on laracasts I came across a pretty nifty tool for Laravel called Clockwork.  Clockwork includes a Google chrome extension and a back-end library on Github.  After configuring both you’ll have a clockwork tab in your inspector in Chrome.  You can use it’s functions to check how long code snippets take to execute, and echo out variables to the inspector just like console.log() in Javascript.  Neat! 🙂

Permalink » No comments

WordPress – Custom length excerpt

If you ever need a custom length excerpt in your wordpress site, and want to leave the excerpt length alone for the rest of the site, you can use wp_trim_words on the content to pull out exactly how many words you want the excerpt to be.

In the following example I made a 10 words excerpt, but you can make it any length you want by changing the number.

<?php echo wp_trim_words(get_the_content(), 10); ?>

Permalink » No comments

Strip links in HTML using Dreamweaver

I was putting together some “preview” HTML pages and needed to make sure the links didn’t go anywhere odd.  So I found out how to quickly strip out all the links from an HTML document using Dreamweaver’s regular expressions and find and replace.

It’s pretty easy, just put this in the find field:

<a href='(.*)’>

and this in the replace:

<a href=’#’>

And make sure to select “Use regular expression,” just like this:

strip_links

Permalink » No comments

Ruby, Haml, and SASS in Dreamweaver CS6

Call me a dinosaur, but I’m still chugging away with Dreamweaver.  I can’t pull myself away from the lovely site management and built in FTP features 🙂

But Dreamweaver lacks support for Ruby, and it’s friends HAML and SASS 🙁  I’ve never gotten HAML and SASS to work 100% with highlighting, but there’s a nice little extension for getting ruby highlighting called “Rubyweaver.”

How can download Rubyweaver from github, https://github.com/cannikin/rubyweaver.  At this time it doesn’t have installation instructions, but I just sent a pull request containing them, so they will probably be there now 🙂  It’s pretty simple, just make certain not to skip the “Run as administrator” step, or the installation won’t take.

Now you can open up ruby files and they’ll have some lovely color coding 🙂  Next, is to make dreamweaver open SASS and HAML files.  There are some tricky steps to get syntax highlighting for SASS, but everything I’ve tried just makes everything pink.  That only really works if you write SASS the same way as you would write CSS.  (I indent my SASS – no curly braces for me!)

In Dreamweaver

  • Go to file>preferences
  • Select File Types/Editors
  • In “Open in code view” add ” .haml .sass”

In notepad

  • Go to C:\Users\~Your Username~\AppData\Roaming\Adobe\Dreamweaver CS6\en_US\Configuration
  • open Extensions.txt
  • on the first line add in ,RB,HAML,SASS
  • change
    HTM,HTML,HTA,HTC,XHTML:HTML Documents
    to
    HTM,HTML,HTA,HTC,XHTML,HAML:HTML Documents
  • and then change
    CSS: Style Sheets
    to
    CSS,SASS:Style Sheets
  • You can also add any other extensions you need to wherever you want.

Now they’ll open up in code view and you’ll be able to search whole folders as well. 🙂

Permalink » No comments

Omit posts with a custom field from WordPress

It took me a while to track this down so I thought I’d post about it.

In a recent project I had the need to omit posts from a WordPress query based on if they had a custom field set to them.

It’s pretty simple once you know how it’s done, imaging you want the ability to remove posts from the homepage by hand.  If you used the custom field name of “hide-me” your query would look like this:

1
query_posts('meta_key=hide-me&meta_compare=NOT EXISTS&meta_value=test');

For “meta_key=hide-me” the hide-me can be whatever custom field you like, and for “meta_value=test” it doesn’t matter at all what you set for “test.”  That’s a little odd, but WordPress needs to have that value, but since you’re only checking weather or not the custom field is there the value doesn’t matter.

The tricky bit it is “meta_compare=NOT EXISTS”  and took a bit of digging to find that.  I had to dig through the documentation of WP_Query to track it down.  It also says that it won’t work for query_posts, but that bit might be out of date, at least for WordPress 3.7.1.  That basically just tell WordPress to check if that custom field doesn’t exist.

It’s pretty easy to use, but I wasn’t able to find a simple write-up on it anywhere and took me a bit of trial and error to get going.  So I thought I’d share 🙂

Permalink » No comments