We're growing into something new. Read More
fstrube

Franklin Strube


Relaunched My Personal Site: toekneestuck.com

I recently (and finally) launched my personal website again with a fully responsive design. It's all coded up in HTML5, CSS3, jQuery, Underscore, and running on Cloudflare. I'm looking for any and all feedback, so let me know what you think! toekneestuck.com

/**
 * JSWire
 */

var JSWire = (function($) {
    
    // Define private variables in extendable object to maintain data
    var PVARS = {
        choice: false, 
    }
    
    
    
    // Private functions
    function private_function() {
        // do stuff
    }
    
    
    // Event binding functions
    function eventFunction(e) {
        e.preventDefault();
        // do stuff

        // access a private function here
        private_function();
    }
    
    
    // This is the object being returned, and thus holds all functions publically avaiable.
    return {
        
        init    : function(opts) {
            
            // extend options requires jquery to work
            PVARS = jQuery.extend(PVARS,opts);
            
            // jQuery event bindings etc
            $('#example').click(eventFunction)

        }
    
    }
    
})(jQuery);



// Start the show. Uncomment the $(function()) calls if
// you're loading this script inbetween the browser's 
// <head> tags and not above the </body> end tag.

//$(function() { 


    JSWire.init({
        choice:true
    });


//})

Your jQuery could be better

It bugs me that so many people write jQuery agnostically towards JS best practices. Here's a way to write your jQuery - and any javascript really - in a safer way. It's called the module pattern. Everything within the JSWire function is private - protecting you from nasty cross scripting attacks. The functions that are returned at the end of the function in the return object - example being the init function. So the idea is in the init function, you would attach your jQuery elements to functions listed privately. This paradigm is especially nice for the public / private variables & functions, a.k.a. info hiding. It's a server side-y thing that can be really powerful when ported to the client side. Keeping things private in JS is achieved via closures - notice all code is written in-between functional brackets {}. Also note that the JSWire function self executes - after the function is defined, it is called and passed the original jQuery object. This is another key to holding private & public variables and functions with JS. Any questions let me know!

Quick bookmarklet: see the window size of any page to examine CSS3 media queries & adaptive layouts

Hey guys! I wrote a javascript bookmarklet that shows you the window / viewport size of any page you're on, to make it super-easy to check out and debug CSS3 media queries and adaptive layouts. Check it out, test it, hack it, and send it back with improvements! And now I sleep. Joss

$timers = Varien_Profiler::getTimers();
$out = "\n";
foreach ($timers as $name=>$timer) {
    $sum = Varien_Profiler::fetch($name,'sum');
    $count = Varien_Profiler::fetch($name,'count');
    $realmem = Varien_Profiler::fetch($name,'realmem');
    $emalloc = Varien_Profiler::fetch($name,'emalloc');
    if ($sum<.0010 && $count<10 && $emalloc<10000) {
        continue;
    }
    $out .= number_format($sum,4)."\t".$count."\t".$name."\n";
}
Mage::log($out);

Log Varien_Profiler output to file

Add this code to the end of index.php to have it log profile data collected by the Varien_Profiler class. This is helpful when you want to get profile data for controllers that don't load the normal layout (eg, Ajax requests). Make sure you have the "Varien_Profiler::enable();" uncommented in your index.php file. Props to David Alger for the code.

Number.prototype.times = function(func){
  for (var i=0; i < this; i++) {
    func();
  };
};

// then you can do this:
3 .times(function(){
  alert('joy!');
});

times

Yes, it's pretty nice to be able to add methods to built-in Javascript classes. I added myself a "times" method to the Number prototype, like what we have in Ruby. So you can do this: 3 .times(function(){ /* repeat this code 3 times */ });

Discussion

Protecting your users from phishing with Apache rules and HSTS | Mikkel H√łgh

Use HSTS to protect your HTTPS-powered website against phishing and man-in-the-middle attacks. Code samples for Apache and nginx.

#!/bin/sh
# Written by Jose P. Airosa (bluekora.com)
# Use this script to safely restart apache deamon.
# This script is ideal to cron restarts where we need to be notified if apache didn't restart.
# If the configuration has any error an email will be sent with a notification and the error.
# If there is no error on apache configuration tree apache will be restarted.

# Apache configuration verification command
# You might need to change this according to your apache configuration
AS=`/usr/sbin/apachectl -t 2>&1`

# The subject of the alert email. This is good if you have your email filtering emails by subject
SUBJECT="APACHE CONFIGURATION ERROR"

# The email address to where the email should be sent
EMAIL="your-email-here"

# Create a temporary file to take the email content
EMAILMESSAGE="/tmp/apachemailmessage.txt"

# Write doen the email content, one echo represents one line
echo "APACHE CONFIGURATION ERROR DETECTED, PLEASE VERIFY:">$EMAILMESSAGE
echo "">>$EMAILMESSAGE
# This last line will append the error
echo $AS>>$EMAILMESSAGE

if [[ $AS =~ "Syntax OK" ]]
        then
                # Restart apache. If this comment doesn't work please try "apachectl -k restart" or "/etc/init.d/httpd restart"
                service httpd restart
        else
                # Command to send the email
                /bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
fi

Apache Restart Guardian (Shell Script)

Use this script to safely restart apache deamon. This script is ideal to cron restarts where we need to be notified if apache didn't restart. If the configuration has any error an email will be sent with a notification and the error. If there is no error on apache configuration tree apache will be restarted.