Skip to content

Instantly share code, notes, and snippets.

View luckyshot's full-sized avatar
🌍
xaviesteve.com

Xavi Esteve luckyshot

🌍
xaviesteve.com
View GitHub Profile
@luckyshot
luckyshot / gist:5338413
Created April 8, 2013 16:55
File-less HTML page!
data:text/html,<title>Hello Data URL</title><p>File-less HTML page!</p>
@luckyshot
luckyshot / gist:5340059
Created April 8, 2013 20:11
JavaScript simplest timer (setInterval)
var t = setInterval(function(){
// Do stuff
},1000);
@luckyshot
luckyshot / gist:5346124
Created April 9, 2013 14:30
JavaScript - Remember page scrolled position
$(document)
.scrollTop( (localStorage.scrollPos) ? localStorage.scrollPos : 0 )
.on('scroll', function() {
localStorage.scrollPos = $(document).scrollTop();
});
@luckyshot
luckyshot / gist:5366726
Last active December 16, 2015 02:59
Browser and client details in JavaScript
/****************************************************
* Website
****************************************************/
// Page title
document.title.substring(0, 200);
// Domain (i.e. gist.github.com)
document.domain;
@luckyshot
luckyshot / gist:5395619
Created April 16, 2013 12:46
PHP Working with files
<?php
// Downloading a file
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=".date('Ymd-His ').$this->query.".csv");
header("Pragma: no-cache");
header("Expires: 0");
// Check if file exists
@luckyshot
luckyshot / gist:5395596
Last active December 16, 2015 06:59
Simple Console system
<?php
public function c($msg, $echo = 0) {
if (!isset($_SESSION['console'])) { $_SESSION['console'] = "";}
if ($echo) {
$buffer = "<pre>".$_SESSION['console']."</pre>";
$_SESSION['console']="";
return $buffer;
}else{
$_SESSION['console'] = $_SESSION['console']."
@luckyshot
luckyshot / gist:5418978
Created April 19, 2013 08:38
JavaScript array loops
// With for..in
var stuff, key;
stuff = [];
stuff[0] = "zero";
stuff[9999] = "nine thousand nine hundred and ninety-nine";
stuff.name = "foo";
for (key in stuff){
if (stuff.hasOwnProperty(key) && String(Number(key)) === key) {
console.log("stuff[" + key + "] = " + stuff[key]);
@luckyshot
luckyshot / gist:5455346
Last active December 16, 2015 15:19
CSS3 Animation & Keyframes
@-webkit-keyframes imageBeat,
@-moz-keyframes imageBeat,
@-ms-keyframes imageBeat,
@-o-keyframes imageBeat,
@keyframes imageBeat {
0% { transform: scale(1); }
2% { transform: scale(1.02); }
5% { transform: scale(1); }
100% { transform: scale(1); }
}
@luckyshot
luckyshot / new_gist_file.less
Created June 25, 2013 10:40
CSS simple transition
/* Twitter Bootstrap LESS mixin */
.transition(@property: all, @duration: 0.2s, @animation: ease-in) {
transition:@property @duration @animation;
}
// Used like
.transition();
.transition(all, .2s);
@luckyshot
luckyshot / new_gist_file
Created September 29, 2013 00:00
Bayesian Rating algorythm
The formula for calculating the Top Rated 250 Titles gives a true Bayesian estimate:
weighted rating (WR) = (v ÷ (v+m)) × R + (m ÷ (v+m)) × C
where:
R = average for the movie (mean) = (Rating)
v = number of votes for the movie = (votes)
m = minimum votes required to be listed in the Top 250 (currently 25000)
C = the mean vote across the whole report (currently 7.0)