Parsing URL Parameters with Swift
Here is an extension you can use in your Swift (v4) projects that makes it easy to parse parameters from a url. Given a url like, "http://example.com/?x=1&y=2", you can extract the x and y parameters into a key, value data structure. Here is the s...
Written by Sean Behan on 09/23/2018
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 = Data(base64Encoded: self) else { return nil } return String(data: data, encoding: ....
Written by Sean Behan on 05/02/2018
How to Parse Query Strings in PHP
Here is a quick snippet for parsing query strings in PHP. You can use the `parse_url` and `parse_str` methods. `parse_str` will create a variable for you populated with results. $url = "http://www.seanbehan.com/path/?param=key"; parse_str(parse_url...
Written by Sean Behan on 12/04/2017
Python String Format Precision of Float
You can use string interpolation in combination with a dictionary for simple formatting. print "My name is %(name)s and I have $%(change)0.2f in change in my pocket!" % { 'name': 'Sean', 'change': 00.23 } # My name is Sean and I have $0.23 in chang...
Written by Sean Behan on 11/20/2013
A Regular Expression to Generate Dash Separated Slugs AKA Pretty URLs
This regular expression matches non alphanumeric characters in a string. r = /[^a-z0-9]{1,}/i You can use it to create URL friendly slugs. slug = "hello world!".gsub(/[^a-z0-9]{1,}/i, '-').downcase # => hello-world In combination wit...
Written by Sean Behan on 08/22/2013
Transform Matching Text with Gsub in Ruby and Regular Expression
Here is a gist that demonstrates how easy it is to transform text using #gsub and a block with Ruby. "Scs Epc Score".gsub (/scs|epc/i) { |i| i.upcase } # => SCS EPC Score For more helpful string extensions in Ruby check out our Ruby Gem on GitHub...
Written by Sean Behan on 06/17/2012
Yield a Block within Rails Helper Method with Multiple Content_tags Using Concat
To clean up some repetitive html coding in views, pass a block of text to a helper function which will wrap it for you the same way, each and every time. For example, I have a 'help' link which will toggle the display of a block of text if a link is click...
Written by Sean Behan on 06/17/2012