Skip to content

Instantly share code, notes, and snippets.

Avatar

Horia Dragomir hdragomir

View GitHub Profile
@hdragomir
hdragomir / cd!.sh
Created Mar 23, 2012
Changes to a directory, creates it first if not already there. Saves me loads of headaches
View cd!.sh
function cd! {
mkdir $1
cd $1
}
@hdragomir
hdragomir / .gitconfig
Created Feb 22, 2012
By Popular demand, my gitconfig file
View .gitconfig
[user]
name = Horia Dragomir
email = horia@hdragomir.com
[github]
user = hdragomir
[alias]
st = status -sb
ci = commit
co = checkout
p = push
@hdragomir
hdragomir / about.md
Created Aug 10, 2011 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer
View about.md
@hdragomir
hdragomir / migrate-photos-to-post-thumbnails.php
Created May 3, 2011
Set images within posts as their thumbnails
View migrate-photos-to-post-thumbnails.php
<?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 Apr 30, 2011
Generate Tweet Buttons at will
View make-tweet-button.js
window.twttr && $('#content a.twitter-share-button').each(function(i, el){
(new window.twttr.TweetButton(this)).render();
});
@hdragomir
hdragomir / $.fn.hint.js
Created Mar 18, 2011
simple input hint plugin
View $.fn.hint.js
$.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 Feb 7, 2011
How to block normal click, but let middle (or control-, command- and shift- ) clicking pass through.
View middle-click.js
$('.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 Dec 15, 2010
Quick jQuery plugin to parse data from an element and store it on the element via jQuery.data
View $.fn.parseData.js
(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 Dec 14, 2010
Quick jQuery plugin to force element redraws
View $.fn.redraw.js
(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 Nov 30, 2010
A simple plugin to cross fade an element's children on rollover.
View jquery.kidFader.js
(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(){