Please, before you write any more SQL interfacing code, you must read up on proper SQL escaping to avoid severe SQL injection bugs like the ones you have here. Also, mysql_query
should not be used in new applications. It's a deprecated interface that's being removed from future versions of PHP. A modern replacement like PDO is not hard to learn and is a safer way to compose queries. $_POST
data never goes directly in a query.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PostageApp::Mailer | |
def mail(headers = nil, &block) | |
# Guard flag to prevent both the old and the new API from firing | |
# Should be removed when old API is removed | |
@_mail_was_called = true | |
m = @_message | |
# Call all the procs (if any) | |
class_default = self.class.default | |
default_values = class_default.merge(self.class.default) do |k,v| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hash | |
def transform_values(recursive = true, &block) | |
Hash[ | |
map do |k, v| | |
[ | |
k, | |
(v.is_a?(Hash) && recursive) ? v.transform_values(&block) : yield(v) | |
] | |
end | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
PF=`ruby -rsecurerandom -e 'puts SecureRandom.base64(40).gsub(/\W/, "")[0,24]'` | |
echo $PF > $1.pf | |
openssl genrsa -des3 -passout pass:$PF -out $1.key 2048 | |
openssl rsa -in $1.key -out $1.pem -passin pass:$PF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Molasses | |
# --------- | |
# | |
# Ths tool produces log/molasses.log that records query activity and a | |
# concise summary of the number of calls made for the rendering of each | |
# page. By default this behavior is only engaged in the development | |
# environment. | |
module Molasses | |
def self.logger |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# == Dependencies =========================================================== | |
require 'optparse' | |
require 'open3' | |
# == Constants ============================================================== | |
PATH_LENGTH_MAX = 255 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config.action_mailer.delivery_method = :postageapp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'benchmark' | |
count = 10e6.to_i | |
Benchmark.bm do |x| | |
x.report(:mod) { count.times { |n| n % 2 == 0 } } | |
x.report(:and) { count.times { |n| n & 1 == 0 } } | |
x.report(:odd) { count.times { |n| n.even? } } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
stringifyPart: function(part) { | |
switch(typeof part) { | |
case 'boolean': | |
case 'number': | |
return String(part) | |
case 'string': | |
return '"' + part.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"' | |
case 'undefined': | |
return 'NULL' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'benchmark' | |
LETTERS = ('a'..'z').to_a.freeze | |
def random_customer_name | |
name = [ ] | |
(rand(10) + 1).times do |