Skip to content

Instantly share code, notes, and snippets.

View michaelward82's full-sized avatar

Michael Ward michaelward82

View GitHub Profile
@michaelward82
michaelward82 / vagrant-provisioning.sh
Last active March 5, 2016 22:47
Helper function to create prettier and more meaningful vagrant provisioning script output. https://github.com/michaelward82/vagrant-provisioning-shell-function-helper for project
exe () {
MESSAGE_PREFIX="\b\b\b\b\b\b\b\b\b\b"
echo -e "$MESSAGE_PREFIX Execute: $1"
LOOP=0
while true;
do
if ! [ $LOOP == 0 ]; then echo -e "$MESSAGE_PREFIX ... "; fi;
sleep 3;
LOOP=$((LOOP+1))
done & ERROR=$("${@:2}" 2>&1)
@michaelward82
michaelward82 / gist:9891934
Created March 31, 2014 13:11
Javascript Array: Get the next existing index
/**
* @param int currentIndex
**/
Array.prototype.nextIndex = function (currentIndex) {
// currentIndex + 1 if in bounds, else 0
return currentIndex < this.length - 1 ? currentIndex + 1 : 0;
}

The new Secure Password Hashing API in PHP 5.5

The [RFC for a new simple to use password hashing API][rfc] has just been accepted for PHP 5.5. As the RFC itself is rather technical and most of the sample codes are something you should not use, I want to give a very quick overview of the new API:

Why do we need a new API?

Everybody knows that you should be hashing their passwords using bcrypt, but still a surprising number of developers uses insecure md5 or sha1 hashes (just look at the recent password leaks). One of the reasons for this is that the crypt() API is ridiculously hard to use and very prone to programming mistakes.

<?php
//add your server aliases here
$servers = array(
"185.14.184.234" => "mcfly.bensmann.no",
"185.14.184.xxx" => "another.server.com",
);
//this script is triggered by this command from the terminal or cron:
//echo "time=`uptime`&df=`df -h`" | curl -s -d @- http://domain.com/path/to/script.php
@michaelward82
michaelward82 / show.html.erb
Created September 8, 2011 12:30
Dynamic page parts in RefineryCMS
<% left_col_content = @page.content_for(:left_column) %>
<% content_content = @page.content_for(:content) %>
<% right_col_content = @page.content_for(:right_column) %>
<% if (!left_col_content && !!content_content && !right_col_content) -%>
<%= render :partial => 'content', :object => @page,
:locals => { :css => "grid_12 alpha omega" } %>
<% end -%>
<% if (!!left_col_content && !!content_content && !right_col_content) -%>
<%= render :partial => 'leftcol', :object => @page,
@michaelward82
michaelward82 / _menu_branch.html.erb
Created August 21, 2011 23:01 — forked from parndt/_menu_branch.html.erb
Limit menu rendering in Refinery CMS
<%
if !!local_assigns[:apply_css] and (classes = menu_branch_css(local_assigns)).any?
css = "class='#{classes.join(' ')}'".html_safe
end
# dom_id DEPRECATED: REMOVE AT 1.1, serves no purpose same with css attributes 'first' and 'last'
dom_id = "id='item_#{menu_branch_counter}'".html_safe if menu_branch.parent_id.nil?
-%>
<li<%= ['', css, dom_id].compact.join(' ').gsub(/\ *$/, '').html_safe %>>
<%= link_to menu_branch.title, menu_branch.url -%>
<% if ( (children = menu_branch.children unless hide_children).present? &&
@michaelward82
michaelward82 / _menu_branch.html.erb
Created August 18, 2011 22:33
Limit menu rendering in Refinery CMS
<%
if !!local_assigns[:apply_css] and (classes = menu_branch_css(local_assigns)).any?
css = "class='#{classes.join(' ')}'".html_safe
end
# dom_id DEPRECATED: REMOVE AT 1.1, serves no purpose same with css attributes 'first' and 'last'
dom_id = "id='item_#{menu_branch_counter}'".html_safe if menu_branch.parent_id.nil?
menu_levels = (RefinerySetting.find_or_set(:menu_sub_levels, '1') if menu_levels.nil?) - 1
-%>
<li<%= ['', css, dom_id].compact.join(' ').gsub(/\ *$/, '').html_safe %>>
<%= link_to menu_branch.title, menu_branch.url -%>