Skip to content

Instantly share code, notes, and snippets.

View muratpurc's full-sized avatar

Murat Purç muratpurc

View GitHub Profile
@muratpurc
muratpurc / html5doctor_css_reset.css
Created June 27, 2016 09:59
html5doctor.com Reset Stylesheet
/*
html5doctor.com Reset Stylesheet
v1.6.1
Last Updated: 2010-09-17
Author: Richard Clark - http://richclarkdesign.com
Twitter: @rich_clark
*/
html, body, div, span, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
@muratpurc
muratpurc / multiline strings
Last active August 29, 2015 14:25
How to creating multi-line strings in JavaScript < ES6
// Alternative way to create a multi-line strings for ES < 6
var text = (function () {/*
<html>
<body>
<div>
</div>
</body>
</html>
*/}).toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1];
console.log('text', text);
@muratpurc
muratpurc / jsonStringify
Created May 26, 2014 21:40
JS: JSON.stringify
// Helper function to convert JSON to it's string representation
var jsonStringify = typeof JSON !== 'undefined' ? JSON.stringify : function(obj) {
var arr = [];
$.each(obj, function(key, val) {
var next = key + ': ';
next += (val === Object(val)) ? jsonStringify(val) : val;
arr.push(next);
});
return '{ ' + arr.join(', ') + ' }';
};
@muratpurc
muratpurc / gist:5966454
Created July 10, 2013 13:52
JS: Simple JavaScript templating
/**
* Simple templating, replaces occurrence of replacements in passed template
* against the values in passed replacements, where the key of replacements will be
* mapped to the items to be replaced.
*
* Usage:
* <code><pre>
* var template = '<a href="{url}" title="{title}">{text}</a>';
* var replacements = {
* url: 'http://www.google.com',
@muratpurc
muratpurc / gist:2314727
Created April 5, 2012 22:36
PHP: Regex to validate different phone number formats
<?php
/**
* Regular expression to validate different types of phone numbers
*/
// simple pattern
$pattern = '/^[0-9\-\(\)\/\+\s]*$/';
// example phone numbers
$phoneNumbers = '
@muratpurc
muratpurc / gist:2008994
Created March 9, 2012 22:12
JS: Simple JavaScript profiler
/**
* Simple profiler, used to measure time taken by processes.
* Usage:
* <pre>
* var profile = new mpProfiler("Measuring async loop");
* i;
* for (i = 0; i < 10; i++) {
* // do something really cpu expensive
* doExpensiveJob(i, 10, function(pos, total){
* profile.addStep("Step " + cur + " from " + total + " done!");
@muratpurc
muratpurc / gist:1341358
Created November 5, 2011 10:08
PHP/CSS: Extract all url definitions (e. g. background images) in CSS declarations
/**
* Extracts all url definitions (e. g. urls to background images) in CSS.
*
* This snippet could be usefull within a build process where css files are
* distributed in different folder during development and should be merged together.
* Existing url definitions could be invalid in some cases.
*/
// example css content, could be read from a file
$cssFileContent = <<<CSS
@muratpurc
muratpurc / gist:1234515
Created September 22, 2011 10:42
HTML/CSS: Cross-Browser tooltip with CSS
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Example Cross-Browser tooltip with CSS</title>
<style type="text/css"><!--
body {
padding-top:130px;
}
#box {
@muratpurc
muratpurc / gist:1234513
Created September 22, 2011 10:39
HTML/CSS: Center a div vertically and horizontally
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>How to center a div vertically and horizontally</title>
<style type="text/css">
#centerBox {
position: absolute;
width: 600px;
@muratpurc
muratpurc / gist:1234502
Created September 22, 2011 10:30
PHP: UTF-8 encoding detection
/**
* Checks, if passed string is utf-8 encoded or not.
*
* @param string $string String to check
* @return int Number of found UTF-8 character
*/
function mp_detectUTF8($string)
{
return preg_match('%(?:
[\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte