Skip to content

Instantly share code, notes, and snippets.

View hdragomir's full-sized avatar

Horia Dragomir hdragomir

View GitHub Profile
@hdragomir
hdragomir / about.md
Created August 10, 2011 20:32 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer
@hdragomir
hdragomir / migrate-photos-to-post-thumbnails.php
Created May 3, 2011 12:54
Set images within posts as their thumbnails
<?php
$thumbnail_width = 593;
$thumbnail_height = 400;
foreach(query_posts('posts_per_page=-1') as $post)
if(! has_post_thumbnail($post->ID))
foreach(get_children('post_type=attachment&post_mime_type=image&post_parent=' . $post->ID) as $image){
$sizes = wp_get_attachment_metadata($image->ID);
if($sizes['height'] >= $thumbnail_height && $sizes['width'] >= $thumbnail_width){
set_post_thumbnail($post->ID, $image->ID);
@hdragomir
hdragomir / make-tweet-button.js
Created April 30, 2011 20:48
Generate Tweet Buttons at will
window.twttr && $('#content a.twitter-share-button').each(function(i, el){
(new window.twttr.TweetButton(this)).render();
});
@hdragomir
hdragomir / $.fn.hint.js
Created March 18, 2011 11:09
simple input hint plugin
$.fn.hint = function(hint){
var val = $(this).eq(0).bind('focus', function(){
$(this).removeClass('hinting');
if($(this).val() == hint) $(this).val('');
}).bind('blur', function(){
if($(this).val() == '') $(this).addClass('hinting').val(hint);
}).bind('change', function(){
$(this).removeClass('hinting');
}).val();
if(! /\S/.test(val)) $(this).eq(0).val(hint).addClass('hinting');
@hdragomir
hdragomir / middle-click.js
Created February 7, 2011 20:25
How to block normal click, but let middle (or control-, command- and shift- ) clicking pass through.
$('.some-snazzy-selector').click(function(ev){
if( ev.which == 2 || ev.metaKey || ev.ctrlKey || ev.shiftKey ){
return true;
}
// Ajax Magic here
});
@hdragomir
hdragomir / $.fn.parseData.js
Created December 15, 2010 08:51
Quick jQuery plugin to parse data from an element and store it on the element via jQuery.data
(function($){
$.fn.parseData = function(){
return $(this).filter('[js-data]').each(function(){
var data = jQuery.parseJSON($(this).attr('js-data')), prop;
for(prop in data)
$(this).data(prop, data[prop]);
}).end();
}
})(jQuery);
@hdragomir
hdragomir / $.fn.redraw.js
Created December 14, 2010 09:45
Quick jQuery plugin to force element redraws
(function($){
$.fn.redraw = function(){
return $(this).each(function(){
var n = document.createTextNode(' ');
$(this).append(n);
setTimeout(function(){n.parentNode.removeChild(n)}, 0);
});
}
})(jQuery)
@hdragomir
hdragomir / jquery.kidFader.js
Created November 30, 2010 12:32
A simple plugin to cross fade an element's children on rollover.
(function($){
$.fn.kidFader = function(){
return $(this).each(function(){
$(this).hover(function(){
$(this)
.children('.hover').stop(1,1).hide().fadeIn('fast')
.end()
.children('.normal').stop(1,1).fadeOut('fast');
}, function(){
@hdragomir
hdragomir / image_resizer.php
Created September 2, 2010 08:48
on the fly image resizer
<?php
define('cache', realpath('./cacheddata/icons/'));
$h = 28;
$w = 28;
$iurl = &$_GET['i'];
$file = cache . DIRECTORY_SEPARATOR . sha1("$w/$h/$iurl").'.jpg';
header("Content-type: image/jpeg");
<html>
<head>
<title>prime number checker</title>
<style>
body, input{
font-family: Georgia, serif;
background-color: white;