This is a simple, but useful little script I ended up writing to test some things. I found it easier to use this than to constantly use the
mail command. It basically wraps action mailer in a small ruby script so you can call it from the command line.
./spoofmail.rb --to=who@where.com --from=sjobs@apple.com --subject='Hey You!' --body='whatsup guy?'
or using STDIN
./spoofmail.rb --to=who@where.com --from=sjobs@apple.com --subject='Hey You!' < body_of_message
cat|./spoofmail.rb --to=who@where.com --from=sjobs@apple.com --subject='Hey You!'
whatsup guy?
^d
It might come in handy one day when you need to mess with a co-worker or test a mail receiver... or something else?
More →
Something I've noticed a lot with PHP developers is how they handle session checking for users. Most people use a simple
$_SESSION['...'] check and if that fails they use a
header('location:...') redirect. I've also noticed that a lot of those same developers miss one key security flaw: not everything respects headers. Here is a small example using cURL to demonstrate what I mean.
More →
I was recently overhauling my permissions for a big rails app and needed to see which filters were on which controllers as an overview. I came up with this little snippet which will go through each of your controllers and print out which filters are on them, as well as their options.
More →
Ever want to break a small PHP app into an MVC-ish convention without the need of tacking on a massive templating engine? Are you opposed to remembering new syntax just for a template? Why not just use some
ob_* code to roll your own simple templating engine?
This will allow you to create PHP includes which will render as templates so you can organize your app into an MVC-ish layout.
More →
This is admittedly ghetto, but I needed a super simple small-scale solution to creating unified diffs based off large blocks of text. The easiest way to do this was by creating temp file and using the native
diff command to do the comparison.
I've used this method for a really small snippets app for our intranet, which can be found
on GitHub.
More →
This one is a pretty specific hack. I've had the need to build mini reporting apps, using Sinatra, that aggregate data from multiple databases and produce a report. This is all fine since ActiveRecord is awesome, but I've always missed AR's query caching ability.
After some digging I found that query caching is only enabled on AR's Base connection and all other models must use that awkward
Model.cache{} construct -- which is annoying to use. I've hacked up a solution that works, although it relies on
:send and
instance_variable_set which isn't very elegant or solid.
For what it's worth, here is a "simple" way to get Sinatra to use ActiveRecord's native query caching for more than 1 database:
More →
I recently had to format large numbers using JavaScript and was really missing Rails'
number_with_delimiter function. Heres a simple version for JavaScript.
More →
Ever need to provide a fuzzy date using PHP for your web app? Heres a simple snippet that will do just that.
More →