Skip to content

Instantly share code, notes, and snippets.

View varemenos's full-sized avatar

Adonis Kakoulidis varemenos

View GitHub Profile
@varemenos
varemenos / em2pxl.js
Created April 20, 2012 18:32
JQuery - 1em to pixels
function em2pxl(){
// how many pixels in 1em
var div = $('<div style="width: 1em;"></div>').appendTo('body');
var em = div.width();
div.remove();
// console.log('1em = ' + em + 'pixels.');
return em;
}
// source: http://forum.jquery.com/topic/how-do-tell-how-many-px-are-in-1em
@varemenos
varemenos / getparam.js
Created April 29, 2012 03:50 — forked from alkos333/gist:1771618
JQuery - GET URL Parameter value
// Given a query string "?to=email&why=because&first=John&Last=smith"
// getUrlVar("to") will return "email"
// getUrlVar("last") will return "smith"
// Slightly more concise and improved version based on http://www.jquery4u.com/snippets/url-parameters-jquery/
function getUrlVar(key){
var result = new RegExp(key + "=([^&]*)", "i").exec(window.location.search);
return result && unescape(result[1]) || "";
}
@varemenos
varemenos / errordoc.htaccess
Created May 1, 2012 07:24
Apache - Custom Error Document Files
ErrorDocument 400 /error-docs/400.html
ErrorDocument 401 /error-docs/401.html
ErrorDocument 403 /error-docs/403.html
ErrorDocument 404 /error-docs/404.html
ErrorDocument 405 /error-docs/405.html
ErrorDocument 500 /error-docs/500.html
ErrorDocument 501 /error-docs/501.html
ErrorDocument 502 /error-docs/502.html
ErrorDocument 503 /error-docs/503.html
@varemenos
varemenos / curl.php
Created May 10, 2012 19:59
PHP - download url content via CURL
<?php
// usage:
curl_download('http://url');
function curl_download($Url){
// is cURL installed yet?
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}
@varemenos
varemenos / verticalcenter.js
Created July 2, 2012 23:48
JQuery - Vertically Center Div
$(document).ready(function(){
$(window).resize(function(){
var target = '#main';
$(target).css({
position:'absolute',
left: ($(window).width() - $(target).outerWidth())/2,
top: ($(window).height() - $(target).outerHeight())/2
});
});
@varemenos
varemenos / checkbox.js
Created August 1, 2012 20:17
JQuery - Label Checks Checkbox
$(function(){
$('.checkboxlabel').click(function(){
if($('.checkboxinput').prop('checked')){
$('.checkboxinput').removeAttr('checked');
}else{
$('.checkboxinput').attr('checked', true);
}
});
});
@varemenos
varemenos / responsive.html
Created February 28, 2013 21:12
Responsive Viewer
<html>
<head>
<meta charset="UTF-8">
<title>simple Responsive viewer by Adonis K.</title>
<link href="//cdnjs.cloudflare.com/ajax/libs/normalize/2.1.0/normalize.css"></link>
<style>
iframe {
transition: 150ms ease;
display: block;
margin: 0 auto;
@varemenos
varemenos / parseUri.js
Last active December 14, 2015 22:49
JavaScript - Parse url parameters
var params = {};
var queryString = location.search.substring(1); // For # params use location.hash
var regex = /([^&=]+)=([^&]*)/g;
var m;
while (m = regex.exec(queryString)) {
params[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
}
@varemenos
varemenos / escape.js
Created April 20, 2013 05:22
JavaScript - Escape HTML special characters
// source: http://stackoverflow.com/a/9251169/649239
var escape = document.createElement('textarea');
function escapeHTML(html) {
escape.innerHTML = html;
return escape.innerHTML;
}
function unescapeHTML(html) {
@varemenos
varemenos / route.php
Last active December 17, 2015 08:39
PHP - Basic URL Routing
<?php
if(!empty($_REQUEST)){
// get real parameters
$parameters = $_REQUEST;
}
if(isset($_SERVER['PATH_INFO'])){
// path = the trimmed PATH_INFO string
// allowed characters:
// {'a','b',..,'z'},{'A','B',...,'Z'},{'0','1',...,'9'},{'_','/','.'}