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 / response.php
Last active December 30, 2019 16:02
Web scraping done right (with cUrl and user agent)
<?php return array (
'url' => 'https://xaviesteve.com/',
'content' => '<!doctype html><html>...</html>',
'cookies' => '__cfduid=d3fa669e1069e72c2e47d127ab9b8e11f1465390629',
'http_code' => 200,
'content_type' => 'text/html; charset=UTF-8',
'header_size' => 578,
'request_size' => 229,
'filetime' => -1,
'ssl_verify_result' => 0,
@luckyshot
luckyshot / simpletemplatingengine.php
Last active May 8, 2017 19:54
Simple Templating Engine
<?php
public function view($filename = 'home') {
// Default values for every View
$data = array(
"app_title" => $this->app_title,
"app_tagline" => $this->app_tagline,
"app_url" => $this->app_url,
"app_version" => $this->app_version,
"user_name" => $this->user_name,
);
@luckyshot
luckyshot / gist:5395607
Last active May 8, 2017 19:54
Array to CSV spreadsheet
<?php
function encodecsv($string) {
if(strpos($string, ',') !== false || strpos($string, '"') !== false || strpos($string, "\n") !== false) {
$string = '"' . str_replace('"', '""', $string) . '"';
}
return $string;
}
@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: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 / css-mini-grid.css
Last active April 5, 2022 19:09
CSS Mini-grid
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
@luckyshot
luckyshot / new_gist_file
Last active December 14, 2017 10:39
Virtual Host in MAMP for Mac OS X Mountain Lion
sudo nano /Applications/MAMP/conf/apache/httpd.conf
-------------------------
NameVirtualHost *
<VirtualHost *>
DocumentRoot "/Users/xavi/Dropbox/WWW"
ServerName localhost
</VirtualHost>
@luckyshot
luckyshot / cookies.js
Last active May 14, 2020 11:01
Cookie JavaScript object methods
/**
* CRUD cookies
* expires is in Days
*/
var _cookieSet = function( name, value, expires, path, domain, secure )
{
var today = new Date(),
expires_date;
today.setTime( today.getTime() );
@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);