Skip to content

Instantly share code, notes, and snippets.

View dehart's full-sized avatar

Michael dehart

  • The Netherlands
View GitHub Profile
@dehart
dehart / smooth.js
Created June 19, 2013 13:45
Jquery Smooth scrolling
$("a").click(function() {
$("html, body").animate({
scrollTop: $($(this).attr("href")).offset().top + "px"
}, {
duration: 500,
easing: "swing"
});
return false;
});
@dehart
dehart / bookmark.html
Created May 28, 2013 09:09
Bookmarkable pages that are loaded by ajax
<a href='#t-rex' onclick='return getDinoInfo("t-rex");'>T-Rex</a><br />
<a href='#brachiosaurus' onclick='return getDinoInfo("brachiosaurus");'>Brachiosaurus</a><br />
<a href='#pterodactylus' onclick='return getDinoInfo("pterodactylus");'>Pterodactylus</a>
<div id='dino-details'></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type='text/javacript'>
$(document).ready(function() {
//makes sure that the window.location.hash exists
@dehart
dehart / detecht_language.php
Created May 28, 2013 07:34
Detect browser language
function get_client_language($availableLanguages, $default='en'){
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$langs=explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach ($langs as $value){
$choice=substr($value,0,2);
if(in_array($choice, $availableLanguages)){
return $choice;
}
}
@dehart
dehart / gist:5656776
Created May 27, 2013 12:17
Saving a PHP array to a PHP file that returns an array
public function save($path, $array)
{
$data = "<?php\nreturn array(";
foreach ($array as $key => $value) {
$data .= "'" . $key . "'=>". var_export($value,true).';' . "\n";
}
$cdata .= "\n);";
//make sure directory exists before creating
return file_put_contents($path, $data);
}
@dehart
dehart / data.php
Last active December 17, 2015 04:59
Loading and sorting an html table using jquery's $.getJSON(); 1. Place on an http server supporting PHP 5.4 2. Load table.html 3. Click on one of the table headers
<?php $results = [
[
"date"=> $_GET['sort'],
"message"=> "User \"Beheerder, Systeem\" has been working for more than 12 hours 19.5 hours total",
"status"=> 0,
"user_name"=> "Beheerder, Systeem"
],
[
"date"=> "22-04-2013 04=>00",
"message"=> "User \"Beheerder, Systeem\" has been working outside office hours on 22-04-2013 04=>00",