Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jookyboi's full-sized avatar

Rui Jiang jookyboi

View GitHub Profile
@jookyboi
jookyboi / localStorageJSON.js
Created March 19, 2011 18:02
Functions to save and load JSON in localStorage
// requires: https://github.com/douglascrockford/JSON-js/raw/master/json2.js
{
saveJson: function(key, json) {
localStorage[key] = JSON.stringify(json);
},
loadJson: function(key) {
var value = localStorage[key];
if (value === undefined || value === null)
return null;
@jookyboi
jookyboi / disableselection.js
Created March 21, 2011 23:09
Disable click-and-drag selection in all browsers through css and javascript
for IE:
function disableSelection(target){
if (typeof target.onselectstart!="undefined") //IE route
target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
target.style.MozUserSelect="none"
else //All other route (ie: Opera)
@jookyboi
jookyboi / ieMaxWidth.css
Created March 23, 2011 16:24
Max width css property for IE
/* From http://perishablepress.com/press/2007/01/16/maximum-and-minimum-height-and-width-in-internet-explorer/ */
* html div#division {
width: expression( document.body.clientWidth > 776 ? "777px" : "auto" ); /* sets max-width for IE */
}
div#division {
max-width: 777px; /* this sets the max-width value for all standards-compliant browsers */
}
@jookyboi
jookyboi / scrollToBottom.js
Created March 27, 2011 21:40
Scroll to bottom of container
$container.scrollTop($container[0].scrollHeight);
@jookyboi
jookyboi / widthOfHiddenElements.js
Created March 29, 2011 19:32
Get width of hidden elements.
var $table = $("#parent").children("table");
$table.css({ position: "absolute", visibility: "hidden", display: "block" });
var tableWidth = $table.outerWidth();
$table.css({ position: "", visibility: "", display: "" });
@jookyboi
jookyboi / replaceUrlsInText.js
Created March 30, 2011 03:41
Linkify urls in plain text.
// from: http://stackoverflow.com/questions/37684/replace-url-with-html-links-javascript
function replaceURLWithHTMLLinks(text) {
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
return text.replace(exp,"<a href='$1'>$1</a>");
}
@jookyboi
jookyboi / GuessNumber.java
Created December 20, 2012 02:45 — forked from brikis98/GuessNumber.java
Some java files
import java.util.Random;
import java.util.Scanner;
public class GuessNumber {
public static void main(String[] args) {
Random generator = new Random();
int toGuess = generator.nextInt(10) + 1;
int guess;
Scanner scanner = new Scanner(System.in);
try {
@jookyboi
jookyboi / Gemfile.rb
Created February 19, 2013 16:30
How to get Unicorn working on Heroku. From http://blog.codeship.io/2012/05/06/Unicorn-on-Heroku.html
gem 'unicorn'
$.url().param('search');
@jookyboi
jookyboi / clone_array.js
Created February 23, 2013 18:57
Clone javascript array
arr.slice()