Skip to content

Instantly share code, notes, and snippets.

View gsdefender's full-sized avatar
💭
I may be slow to respond.

Emanuele Cipolla gsdefender

💭
I may be slow to respond.
View GitHub Profile
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
@sebzur
sebzur / polish_holidays.py
Created February 12, 2012 20:25
Python generator for public holidays in Poland
from datetime import date, timedelta
from dateutil import easter
from dateutil.relativedelta import *
def get_holidays(year=2010):
""" Returns Polish hollidays dates (legally considered non-working days) """
easter_sunday = easter.easter(year)
holidays = {'New Year': date(year,1,1),
'Trzech Kroli': date(year,1,6),
'Easter Sunday': easter_sunday,
@8ig8
8ig8 / remote-upload-image.php
Created April 17, 2012 03:50
How To Locally Mirror Remote Images With WordPress
<?php
/*
How To Locally Mirror Remote Images With WordPress
Source: http://forrst.com/posts/Locally_Mirror_Remote_Images_With_WordPress-XSE
*/
// URL of the image you want to mirror. Girl in pink underwear for instance.
$image = 'http://i.imgur.com/Hq4QA.jpg';
@franz-josef-kaiser
franz-josef-kaiser / ajax.js
Last active September 5, 2024 01:43
AJAX in WordPress. Class based example.
( function( $, plugin ) {
"use strict";
// Working with promises to bubble event later than core.
$.when( someObjectWithEvents ).done( function() {
console.log( 'AJAX request done.' );
} )
.then( function() {
setTimeout( function() {
console.log( 'AJAX requests resolved.' );
@hissy
hissy / gist:7352933
Created November 7, 2013 11:07
[WordPress] Add file to media library programmatically
<?php
$file = '/path/to/file.png';
$filename = basename($file);
$upload_file = wp_upload_bits($filename, null, file_get_contents($file));
if (!$upload_file['error']) {
$wp_filetype = wp_check_filetype($filename, null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_parent' => $parent_post_id,
function git_likely_authority() {
# Outputs a ranked list of likely author(itie)s regarding tracked files matching *${1}*
# (Makes it easier to discover who likely knows most about the matched files)
# (Note: Not always indicative if large refactors/renamings have occurred)
# E.g. `git_likely_authority some_pattern_that_matches_a_path`
git ls-files "*${1}*" |
grep -v -E 'node_modules|vendor' | # edit to avoid certain files/dirs
xargs -n1 git blame --line-porcelain |
sed -n 's/^author //p' |
sort -f |
@d3noob
d3noob / .block
Last active September 16, 2020 09:18
Map using leaflet.js and d3,js combined
license: mit
@ichord
ichord / gist:9808444
Created March 27, 2014 14:12
demo of using pdf.js to extract pages to images
<script src="http://cdnjs.cloudflare.com/ajax/libs/processing.js/1.4.1/processing-api.min.js"></script><html>
<!--
Created using jsbin.com
Source can be edited via http://jsbin.com/pdfjs-helloworld-v2/8598/edit
-->
<body>
<canvas id="the-canvas" style="border:1px solid black"></canvas>
<input id='pdf' type='file'/>
<!-- Use latest PDF.js build from Github -->
@kgundula
kgundula / boundbox
Last active September 22, 2016 15:43
Calculate distance between two sets lat/lon coordinates and Calculate destination lat/lon given a starting point lat/lon cordinates, bearing, and distance, and Calculate the bounding box
// Calculating the bounding box
function boundbox ($lat, $lon, $distance, $units="km") {
return array ( "N" => getDestinationCoordinates ($lat,$lon, 0,$distance,$units),
"E" => getDestinationCoordinates ($lat,$lon, 90,$distance,$units),
"S" => getDestinationCoordinates ($lat,$lon, 180,$distance,$units),
"W" => getDestinationCoordinates ($lat,$lon, 270,$distance,$units));
}
#!/bin/bash
# credits to: https://gist.github.com/2called-chaos/4285767
# Install:
# curl -O https://gist.githubusercontent.com/ziogaschr/74884b8d5095c86a7cef/raw/d236c87d89a34b588f37838843279e8e02f073e9/setup-autossh-tunnel.sh
# chmod u+x setup-autossh-tunnel.sh
# ./setup-autossh-tunnel.sh
#
# Extra:
# it is good to make a new user on both host and remote (http://linuxaria.com/howto/permanent-ssh-tunnels-with-autossh)
# useradd -m -s /bin/false autossh