Skip to content

Instantly share code, notes, and snippets.

View taufik-nurrohman's full-sized avatar
🍁
I ❤ U

Taufik Nurrohman taufik-nurrohman

🍁
I ❤ U
View GitHub Profile
@taufik-nurrohman
taufik-nurrohman / universal-slug-url-generator.js
Created February 11, 2015 15:54
JavaScript Universal Slug URL Generator
/**
* Usage:
* ------
*
* <input type="text"> &rarr; <input type="text">
*
* <script>
* var input = document.getElementsByTagName('input');
* slug(input[0], input[1]);
* </script>
ּ_בּ
בּ_בּ
טּ_טּ
כּ‗כּ
לּ_לּ
מּ_מּ
סּ_סּ
תּ_תּ
٩(×̯×)۶
٩(̾●̮̮̃̾•̃̾)۶
@taufik-nurrohman
taufik-nurrohman / extract-html-attributes.php
Created January 17, 2015 00:45
Regex to Extract HTML Attributes
<?php
/*! Based on <https://github.com/mecha-cms/cms/blob/master/system/kernel/converter.php> */
function extract_html_attributes($input) {
if( ! preg_match('#^(<)([a-z0-9\-._:]+)((\s)+(.*?))?((>)([\s\S]*?)((<)\/\2(>))|(\s)*\/?(>))$#im', $input, $matches)) return false;
$matches[5] = preg_replace('#(^|(\s)+)([a-z0-9\-]+)(=)(")(")#i', '$1$2$3$4$5<attr:value>$6', $matches[5]);
$results = array(
'element' => $matches[2],
'attributes' => null,
'content' => isset($matches[8]) && $matches[9] == '</' . $matches[2] . '>' ? $matches[8] : null
@taufik-nurrohman
taufik-nurrohman / slugify.php
Created January 14, 2015 01:00
Slug URL Generator
<?php
function do_slug($text, $lower = true, $strip_underscores_and_dots = true, $connector = '-') {
$text_accents = array(
// Numeric characters
'¹' => 1,
'²' => 2,
'³' => 3,
// Latin
'°' => 0,
@taufik-nurrohman
taufik-nurrohman / php-html-css-js-minifier.php
Last active February 23, 2024 04:30
PHP Function to Minify HTML, CSS and JavaScript
<?php
// Based on <https://github.com/mecha-cms/x.minify>
namespace x\minify\_ { // start namespace
$n = __NAMESPACE__;
\define($n . "\\token_boolean", '\b(?:true|false)\b');
\define($n . "\\token_number", '-?(?:(?:\d+)?\.)?\d+');

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

<iframe frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?hl=ru&amp;ie=UTF8&amp;output=embed&amp;q={address}"></iframe>
// http://ideone.com/Q5USEF
<?php
function minify_css($str){
# remove comments first (simplifies the other regex)
$re1 = <<<'EOS'
(?sx)
# quotes
(
<?php
function curry() {
$curryArgs = func_get_args();
return function() use ($curryArgs){
$function = array_shift($curryArgs);
$mergedArgs = array_merge($curryArgs, func_get_args());
return call_user_func_array($function, $mergedArgs);
};
}
function setVisibleTimeout(callback, delay) {
var id = null,
t = 0,
prefix = '';
'o webkit moz ms'.replace(/\S+/g, function(p) {
if ((p + 'Hidden') in document) {
prefix = p;
}
});
function onVisibilityChange(event) {