SQLTerminal.app
now available
Want fresh tech tips in your inbox?
XPath Expression Editor
Practice and improve your XPath skills with XPath Editor
Click to buy on the App Store
Photo Location Changer
Easily change the location on your photos and videos
Click here for more info about the app
Photo Date Changer
Easily change the dates and times on your photos and videos
Click here for more info about the app
VocabReminder
English dictionary with notifications so you won't forget what you're studying!
Click here for more info about the app
VocabQuiz
The app that quizzes and scores you on your vocabulary!
Click here for more info about the app

Posts Tagged with "Code"

How to Just Get SQL Statement Error with SQLAlchemy Python Database Wrapper

If you're working with SQLAlchemy, the best database driver for Python, and want to see only SQL syntax errors, you need to use the StatementError ex...


Extension for Encoding and Decoding Strings in Base64 in Swift

Here is an extension to base 64 encode and decode strings in Swift (3) extension String { func fromBase64() -> String? { guard let data...


How to Log and Query SQL Queries Hitting Your Database with MySQL

Here is some code just in case you want to look at and query the queries hitting your MySQL database. Enter this from the mysql client console....


How to Filter or Search HTML with Vanilla Javascript - No JQuery Required

The basic approach is to use the `document.querySelectorAll` to match certain elements, then manually set the display property to 'none' or 'block' (o...


How to Make an iOS App Icon from a File on the Command Line or Web Browser

If you need to make iOS app icon assets from a photo, take a look at the [Make App Icon](https://makeappicon.com/) website and API. They will let you...


How to Calculate Age with PHP

Calculate age in PHP $your_birthday = '1982-08-29'; $difference = date_diff(date_create(), date_create($your_birthday)); $age = $differe...


How to Use Named Variables with Postgres and PHP PDO Driver

You can write reusable scripts with Postgres by taking advantage of named variables. A named variable starts with a `:` in your sql script. Here i...


Connect to Postgres on Heroku using DATABASE_URL Config Var with PHP and PDO

Unfortunately PHP's PDO constructor doesn't take a database connection url (in a format that Heroku makes available as a config var) as an argument. I...


How to Slugify a String in PHP

Here is a snippet for generating a URL friendly slug in PHP function slugify($string){ return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/...


Manual ManyToMany Through with Django's ORM

Here is a code snippet that demonstrates how to set up a __ManyToMany through__ relationship in Django. In Rails, the equivalent would be called a __h...


Active Admin Rails 5 undefined method per_page_kaminari

If you run into this error in development, using Rails 5 and Active Admin NoMethodError - undefined method `per_page_kaminari' Try the followin...


Regex for Extracting URLs in Plain Text

Here is a Regex for extracting URLs from text. However, these links will not already be hyperlinked or source attribtues from images or iframes. T...


I Just Published My First PHP Package HTMLXPATH

I just wrote and published my first PHP package on Packagist.com. It's available on [packagist.org](https://packagist.org/packages/htmlxpath/htmlxpath...


How to send email with Python, smtplib and Postmark

Here is a quick code snippet showing how to send email via SMTP with Postmark without any dependencies. It assumes you are using Heroku and have added...


Reshape an Array of Form Inputs for Flask with getlist()

This is how to reshape an array using Python without Numpy. This is a fairly simple task but it can be a little confusing to wrap your head around....


How to Fix xcrun: error: unable to find utility "instruments", not a developer tool or in PATH

I just got a new machine and downloaded XCode. I used git to clone my ReactNative project from Github. I have everything ready to go. But when I run `...


Deploying Wordpress on Heroku

> This post is out of date - Heroku officially supports PHP now w/ buildpacks Heroku runs Apache version 2.2.22 PHP version 5.3.10 Deployi...


Turn Off SSL Verification In Ruby

The following code will disable SSL verification when using Open SSL. OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE It is probably no...


Generate a Gravatar URL with Ruby

To get a Gravatar you need to hash an email address with the MD5 algorithm. MD5 is a part of the Ruby standard library. Rails loads it by default,...


Installing Ruby with RVM without Xcode using CLANG

I am not using the full Xcode package on my laptop. Instead I'm using the command line tools, offered by Apple as a separate and much smaller instal...


How To Add A Route With A Forward Slash in Params with Rails 3 Application

Use an asterisk in the pattern to match for everything after it. In the example below, date will be available in the params hash as params[:date]....


How to Add Additional Sub Directories to the Default Rails Test:Unit File Structure

# Edit Rakefile in project root # # Add a new rake test task... E.g., rake test:lib, below everything else in that file... # Alternatively, add...


Class

# Define a class with a class method "find" # Usage # Apple.find("macintosh") class Apple def self.find(variety) # code goes here e...


How to Recover a Mistakenly Deleted Branch

Workflow git checkout -b _new_branch_name # do some work and commit changed git checkout master git branch -d _new_branch_name # doh... i meant...


How To Get A List of All Registered Mime Types in Rails

When mime types are registered they are placed in a hash constant EXTENSION_LOOKUP in the module Mime. For reference, the file with the relevant code...


Git Feature Branch Naming Strategy

There are only two hard things in Computer Science: cache invalidation and naming things. -- Phil Karlton Typically, we have...


My First Ruby Gem: Hashed_Attributes

I just wrote and released my first Ruby Gem, Hashed Attributes https://rubygems.org/gems/hashed_...


Link to jQuery Source from Google's CDN

https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js That is the link to the jQuery source hosted by Google on their CDN. It's probably a...


Simple String Concatenation of a Collection Written as a Helper for Rails

At Railsconf last week I took Greg Pollack's online course Rails Best Practices....


Reusing Scopes (Formerly Named_scope) In Rails 3

You can easily chain scopes together in your models. class Article < ActiveRecord::Base scope :ordered, order('position ASC') scope :publis...


Installing MatPlotLib on OS X for Python Version 2.6.1 with PIP and VirtualEnv

If you thought you had installed matplotlib only to find this File "/Library/Python/2.6/site-packages/matplotlib-0.91.1-py2.6-macosx-10.6-unive...


Rails Select Tag and Onchange Event Calling a Remote Function with Default Option Selected

Here is a little code snippet that will fire off a request to update_client_path when you change the select field. This stands alone, rather than bein...


Have Git Email Committers After Pushes

You need a Mail Transfer Agent MTA on the server. The easiest way is to install Sendmail, which Git uses by default. apt-get install sendmail <...


Repost

This post is inspired by http://pupeno.com/blog/really-resetting-the-database/#commen...


A List of Every High School in the United States in Pipe Delimitted Form (2005)

Here is a text file containing every high school in the United States(2005), including city, state, zip code and high school name. <a href='http://s...


The Context of Markup vs Expressions of Equality in Determining the Meaning of Angled Brackets

In the Wordpress editor (html mode) you'll need to become friends with < and > if you plan on showing any code (php, html... xml, most languages...


TODO and Custom Annotations in Rails Applications

While writing software it's common to leave comments for your future self. For instance, if you have written some code but realize that it should be r...


How Beautiful is Ruby?

Working with Ruby and in particular Rails, it's easy to take the beauty inherent in the language for granted. I mean look at this code. If you read it...


How to Import/Export Your Wordpress Blogroll... er, Your Links

It's not immediately apparent how to import/export the links in your Wordpress blogroll. One would expect that the import/export tool, used to backup/...


How to Check if the Current Logged In User can Edit a Course in MOODLE Using the Has_capability Function

After an hour of fruitless searching through the docs and forums, I finally found an answer to my simple question, of course buried in the depths of t...


Moodle's Most Important Function Gets No Attention

Arguably the most important function in the Moodle API, is the create_course function. One would think... after all Moodle is an LMS. Courses are the...


Get Child Categories of Parent Category on Single Post in Wordpress

I was hoping to find a function in the Wordpress API, that goes something like this... the_child_categories("Vermont"); // print Burlington,...


My Review of Moodle 1.9 Extension Development

I wrote a review for Joseph Thibault's Moodle News on extension development for Moodle. The book is quite good and...


Intercepting the Wordpress Loop with Pre_get_posts

#deprecated (see http://codex.wordpress.org/Function_Refe...


Why are PHP5 Namespaces Defined Using a Backslash?

Why are PHP namespaces defined using a backslash? It looks ugly. Unless of course, there is a good reason for the "\"? Does this namespaced code run m...


Onchange Event Fired from Select Field in Rails Form

In the view there is a regular Rails form and a javascript function that will be triggered when the country select field is changed. The javascript fu...


Extending Rails Form Builders

Extending forms in Rails is simple and will greatly reduce the amount of code in your views. This example is taken right from the Agile Web Developmen...


Install and Serve a Rails Application from PHP Subdirectory Using Apache, Phussion Passenger and Ruby Enterprise Edition

Here is how to install a Rails application out of a subdirectory (rather than as a subdomain) with the Apache web server(Apache2). In this example I'm...


PHP Paypal IPN Script

Simple script for posting a valid response back to Paypal service after a sale is completed using the Paypal Instant Checkout payment method. &l...


Managing Timestamps in MySQL with a Trigger

MySQL doesn't support having two columns with time stamping on both initialization and/or on updating at the same time. It would be nice to be able to...


Mod_Python and Web.py on Ubuntu

Download First install mod_python for Apache and then restart/reload the server. apt-get install libapache2-mod-python /etc/init.d/apac...


Accessing Links in Nested TD Cells with Prototype

There must be a better way to do the following with PrototypeJS. I want to loop over nested links inside of table td cells and apply a class to the r...


TinyMCE Rich Text Editor: HELLO EDITOR Plugin Tutorial and Example

I wanted to create a button for the TinyMCE Rich Text Editor for Wordpress. It was tough to find good docs on the subject. There are a couple of usefu...


link_to_function Rails Ajax Reference

Link_to_function syntax for Haml template. Notice the "|" pipe which will allow for new lines in your code. = link_to_function( "Add Line Item")...


Build Your Own Calendar in Rails without any Plugins in less than 10 lines of Ruby Code

There are a number of terrific calendar plugins for Rails. But it's almost as easy, if not easier, to implement your own calendar. The steps are pret...


Override to_param method in model to get pseudo permalinks without any work

There are a number of permalink plugins for Rails, http://www.seoonrails.com/even-better-looking-urls-with-permalink_fu, is a good one that I've used...


Installing Redis Server and Client on Mac OS X and Ubuntu

wget http://redis.googlecode.com/files/redis-0.900_2.tar.gz tar xzvf redis-0.900_2.tar.gz cd redis-0.900 make mv redis-server /usr/bin/ mv redis...


Double Click Event Using Prototype Javascript Framework

Super simple to get double click "desktop" like functionality out of Prototype! For some reason, googling it doesn't yield many useful results. http:/...


OpenSSL Certificate Generation Information for Certificate Authority to Serve Traffic Over Https

apt-get install openssl openssl genrsa -des3 -out server.key 1024 openssl req -new -key server.key -out server.csr You'll be prompted to...


Destroy Children In Rails 2.3

In the parent class place the following code has_many :posts, :dependent => :destroy This used to be accomplished with has_many :p...


Email Obfuscation and Extraction from Text with Rails

There is a helper method for handling the obfuscation of email addresses in Rails. mail_to "me@domain.com", "My email", :encode => "hex" # => <...


Protect a Directory with Apache, .htaccess and httpasswd

Apache comes with a command line utility called "htpasswd". This utility will generate a username and password that you can use to authenticate agains...


Dot htaccess file for wordpress installation (.htaccess)

Login to your wordpress installation and scroll to and click the second to last link set "Settings". You'll need to configure wordpress to handle your...


Rails Prototype JS and TinyMCE Autosave

TinyMCE is a nice little WYSIWYG for text processing online. It uses iFrames and Javascript callbacks to manipulate textarea form fields. Using it wit...


Validate Uniqueness on Join Tables in Rails

How to validate uniqueness in a :has_many :through relationship with Ruby on Rails. You'll need three models in this example List, Subscriber and List...


Using Prototype to Access Form Data

Prototype has a powerful API for accessing and manipulating the Document Object Model, A.K.A the DOM. The following code will let you interact with a...


paypal ipn simulator

If you use the Paypal sandbox you'll notice that there is an IPN Simulator test tool. You must be logged to use it. This tool lets you test an IPN han...


rails fixtures: using the right timestamp

Fixtures in Rails allow you to quickly and easily populate a database with sample data. They are great when testing your app and you need to test agai...


Setting up a new ubuntu server with apache2, php, ruby on rails, rubygems, mysql, and git

Here are a list of commands to get up and running with Apache2 with Phussion Passenger for Rails, PHP5, MySQL5, Ruby on Rails with Gems, and the sourc...