February 6th, 2010 by jeremychone | No Comments »
Yes, File.renameTo is used to move file.
// File (or directory) to be moved
File file = new File("filename");
// Destination directory
File dir = new File("directoryname");
// Move file to new directory
boolean success = file.renameTo(new File(dir, file.getName()));
if (!success) {
// File was not successfully moved
}
source
Posted in Java | No Comments »
February 5th, 2010 by jeremychone | No Comments »
HTML
Javascript code
<script type="text/javascript">
$(document).ready(function(){
var paper = Raphael("rtest", 320, 200);
var circle = paper.circle(50, 40, 30);
circle.attr({
"stroke": "#336699",
"fill": "#fbfbfb"
});
$(circle.node).click(function(){
var circle = this.raphael;
//Toggle the circle fill color
if (circle.attr("fill") == "#333333") {
circle.attr("fill", "#fbfbfb");
} else {
circle.attr("fill", "#333333");
}
});
});
</script>
See RaphaelJs Event doc
Posted in RaphaelJs, jQuery | No Comments »
February 3rd, 2010 by jeremychone | No Comments »
Posted in Html | No Comments »
February 1st, 2010 by jeremychone | No Comments »
This will focus and select the text of a given input. Nice to help the user doing the most likely action.
$("input[name='First Name']").focus().select();
Posted in jQuery | No Comments »
January 23rd, 2010 by jeremychone | No Comments »
List the file systems
Size given folder
Sort/List largest directories/subdirectories
du /var/log/ | sort -nr | less
Other Links
Posted in Linux | No Comments »
January 18th, 2010 by jeremychone | No Comments »
bubbleBind is a jQuery plugin to conveniently bind bubbling events for given child targets. It is very similar to jQuery.bind and uses it under the cover (as well as jQuery.is()). Nothing magic, just simple, convenient, and familiar.
Example
<div id="parentDiv">
<span>one</span>
<span>two</span>
</div>
$("#parentDiv").bubbleBind("span","click",function(){
alert("you clicked on an span tag: " + $(this).html());
});
Plugin code
License free: use as you want, modify as you can, attribute as you feel.
(function($) {
/**
* Allow to bind a bubbled-event at the parent level for a given child (matching the childSelector).
* The selected element(s) will be considered the parent(s), and the childSelector will filter the target element.
* If, an only if, the target match the childSelector, then, the handler will be called. The key work "this" will
* point to the target document element (as in jQuery bind)
*
* Example:
* $("#parentDiv").bubbleBind("span","click",function(){
* alert("you clicked on an span tag: " + $(this).html());
* });
*
* @param {String} childSelector the jQuery selector for the targeted child. This will be use in $target.is(childSelector)
* @param {String} a jQuery evenType (same a jQuery bind)
* @param {Function} the handler function
*
* TODO: need to support eventData
*/
$.fn.bubbleBind = function(childSelector,eventType,handler) {
// iterate and reformat each matched element
return this.each(function() {
var $parentElement = $(this);
//bind the even to the parent
$parentElement.bind(eventType,function(event){
//get the target and test the target against the childSelector
var $target = $(event.target);
if ($target.is(childSelector)){
// If matched, call the handler method using the target html element as reference
// Note: Might be a smarter and more conventional way to do this. Feel free to suggest.
$target.get(0).bubbleBindHandler = handler;
$target.get(0).bubbleBindHandler(event);
}
});
});
};
})(jQuery);
Posted in jQuery | No Comments »
January 18th, 2010 by jeremychone | No Comments »
Should be in file jquery.samplePlugin.js
(function($) {
/**
* Skeleton for jQuery plugin
* @param {Object} options
*/
$.fn.samplePlugin = function(options) {
// extends options with the default one
var opts = $.extend({}, $.fn.samplePlugin.defaults, options);
// iterate and process each matched element
return this.each(function() {
var $this = $(this); // jQuery object for this element
//do what is needed
});
};
// samplePlugin default options
$.fn.samplePlugin.defaults = {};
})(jQuery);
Posted in jQuery | No Comments »
January 17th, 2010 by jeremychone | No Comments »
JSONP quick sample with Twitter
var tweeturl = "http://search.twitter.com/search.json?count=2&q=HAITI&callback=?";
$.getJSON(tweeturl, function(data){
$.each(data.results, function(i, item) {
$('<p></p>')
.addClass(i%2 ? 'even' : 'odd')
.html(item.text)
.prepend("<img src='" + item.profile_image_url + "' />")
.appendTo('#testDiv');
});
});
Services supporting JSONP
Feel free too add new one as comment I will update this page
Posted in JavaScript | No Comments »
January 11th, 2010 by jeremychone | No Comments »
Edit the from git/share/git-gui/lib/database.tcl and change
if {$objects_current >= $object_limit} {
set objects_current [expr {$objects_current * 250}]
set object_limit [expr {$object_limit * 250}]
if {[ask_popup \....
by:
if {$objects_current >= $object_limit && false} {
set objects_current [expr {$objects_current * 250}]
set object_limit [expr {$object_limit * 250}]
if {[ask_popup \....
Source: Stackoverflow: How to skip “Loose Object” popup when running ‘git gui’
Posted in Git | No Comments »
January 8th, 2010 by jeremychone | No Comments »
When git-am fails to cleanly apply It will ask you to apply it yourself, to git add the file and to run git-am --resolved.
In fact, git-am can help you a lot. When the call to git-am for a patch fails, simply run :
git-am --3way
Il will merge the file that can be automatically merge. Some files may be marked with CONFLICT and in this case, edit them to do a manual merge, and once they are fixed and run
git add $FILES_IN_CONFLICT
git-am --resolved
Posted in Git | No Comments »