Skip to content

Instantly share code, notes, and snippets.

View dehart's full-sized avatar

Michael dehart

  • The Netherlands
View GitHub Profile
@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",
@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 / 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 / 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 / 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 / Loadonscroll.js
Created June 19, 2013 13:47
Load on scroll
var loading = false;
$(window).scroll(function(){
if((($(window).scrollTop()+$(window).height())+250)>=$(document).height()){
if(loading == false){
loading = true;
$('#loadingbar').css("display","block");
$.get("load.php?start="+$('#loaded_max').val(), function(loaded){
$('body').append(loaded);
$('#loaded_max').val(parseInt($('#loaded_max').val())+50);
$('#loadingbar').css("display","none");
@dehart
dehart / tree
Created August 14, 2013 15:08
Tree transition
<html>
<head>
<title>Nooooo!</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<style>
li {
position:relative;
}
a.collapsed + ul {
opacity: 0;
@dehart
dehart / div.html
Created December 17, 2013 10:50
Shrinking dialog
<html>
<head>
<title>Center dialog that shrinks!</title>
<style>
body {padding:0;margin:0;}
#floater {float:left; height:50%; margin-bottom:-300px;}
#content {clear:both; height:100%; position:relative; max-height: 600px; max-width: 700px; box-shadow: inset 0 0 10px #000000; margin: 0 auto;}
</style>
</head>
<body>
@dehart
dehart / replace.php
Created December 18, 2013 10:43
Change config array with regex
<?php
$boolean = true;
$array = <<<'EOT'
[
'db'=>'mydb',
'user'=>'root',
'pass'=>'',
'host'=>'localhost',
function q(expr, con) {
return [].slice.call((con || document).querySelectorAll(expr));
}