Skip to content

Instantly share code, notes, and snippets.

@mellowsh
mellowsh / Single Value from mysqli PHP.php
Created April 2, 2017 04:34 — forked from bcamarneiro/Single Value from mysqli PHP.php
Return single value from mysqli PHP
$name = $mysqli->query("SELECT name FROM contacts WHERE id = 5")->fetch_object()->name;
@mellowsh
mellowsh / gist:6058496
Created July 22, 2013 23:05
Checks for hash in URL and enables themes via body class in CSS.
if (window.location.hash) {
var theme = window.location.hash.split('#')[1];
$("body").removeClass(function (index, css) {
return (css.match(/\btheme-\S+/g) || []).join(' ');
});
$("body").addClass(theme);
}
<!-- Prevent FOUC (flash of unstyled content) -->
<style type="text/css">
.no-fouc {display: none;}
</style>
<script type="text/javascript">
document.documentElement.className = 'no-fouc';
// add to document ready: $('.no-fouc').removeClass('no-fouc');
</script>
@mellowsh
mellowsh / twitter-bootstrap-alert.php
Created January 31, 2013 17:52
Little function to echo out a dismiss-able alert utilizing Twitter Bootstrap's style.
function alert($text,$type) {
echo '<p class="alert alert-' . $type . '" fade in>
<button type="button" class="close" data-dismiss="alert">&times;</button>
' . $text . '
</p>'."\r\n";
}
alert('Request completed successfully!', 'success');
@mellowsh
mellowsh / age.php
Created January 30, 2013 16:12
Super simplistic snippet that calculates the age of something.
function age($date) {
list($year, $month, $day) = explode("/", $date);
$age = date("Y") - $year;
if(date("m") < $month || (date("m") == $month && date("d") < $day)) {
$age--;
}
return $age;
}
echo age("1985/01/01");