Skip to content

Instantly share code, notes, and snippets.

javascript: var s;
/*Figure out the selected text*/
if ( window.getSelection ) {
s = window.getSelection();
} else if ( document.getSelection ) {
s = document.getSelection();
} else {
s = document.selection.createRange().text;
}
/*If there isn't any text selected, get user input*/
@karmiphuc
karmiphuc / reset-checked-radio-buttons.html
Created January 13, 2014 12:00
Special approach, to reset the radio button that has been checked, in case there's no default checked buttons. Cannot use normal approach "$(object).removeAttr('checked')"
<!-- There is no default checked button -->
<input type="radio" name="my-radio" value="0">Choice 1</input>
<input type="radio" name="my-radio" value="1">Choice 2</input>
<input type="radio" name="my-radio" value="2">Choice 3</input>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
// Global index
var rdoActiveIndex = -1;
@karmiphuc
karmiphuc / CheckKeypress.js
Created January 16, 2014 02:17
Keypress Validation ALLOW CHARACTERS: a..z A..Z 0..9 - _ . , @ Reference keycode table: http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
$('input').bind('keypress', function(e) {// Kami.2013.12.24.10:57 Allow only letters, numbers, and @ , . - _
var allowedCode = [8, 13, 32, 44, 45, 46, 95];
var charCode = (e.charCode) ? e.charCode : ((e.keyCode) ? e.keyCode :
((e.which) ? e.which : 0));
if (charCode > 31 && (charCode < 64 || charCode > 90) &&
(charCode < 97 || charCode > 122) &&
(charCode < 48 || charCode > 57) &&
(allowedCode.indexOf(charCode) == -1)) {
e.preventDefault();
$('.alert-box.onerror').html('<h3>ALLOW CHARACTERS: a..z A..Z 0..9 - _ . , @</h3>').fadeIn();
@karmiphuc
karmiphuc / vn_tumblr_bloggers.html
Last active January 3, 2016 20:19
Interesting Vietnamese Tumblr Bloggers
http://dentoi.tumblr.com/
http://cuckikicuc.tumblr.com/
http://december-meow.tumblr.com/
http://taitran.tumblr.com/
http://chuyendoivovan.tumblr.com/
http://khuya.net/
http://dattentoanbitrung.tumblr.com/
http://linhhonda.tumblr.com/
http://nguyen-hoang-huy.tumblr.com/
http://tixiuxiu.tumblr.com/

Setup

git clone <repo>

clone the repository specified by ; this is similar to "checkout" in some other version control systems such as Subversion and CVS

Add colors to your ~/.gitconfig file:

@karmiphuc
karmiphuc / urlParsing.php
Last active January 3, 2016 20:39
URL Parsing from text
<?
function parseUrl($s) {
$__ = preg_replace('/([A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&~\?\/.=]+)/i', '<a href="$1" target="_blank">$1</a>', $s);
return preg_replace('/(^| )([^\/])((www|[^\/\. ]+)\.[A-Za-z]+(\b|$|))/i', '$1<a href="http://$2$3" target="_blank">$2$3</a>', $__);
};
$s = 'Tinhte.vn asdasd google.com asdjaskdjajks www.abc.com xxx Google http://google.com.vm/search/asdajs.html';
var_dump(parseUrl($s));
@karmiphuc
karmiphuc / urlParsing.js
Created January 20, 2014 08:05
URL Parsing from text
String.prototype.parseURL = function() {
return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&~\?\/.=]+/g, function(url) {
return url.link(url);
});
};
String.prototype.parsePseudoURL = function() {
return this.replace(/(^| )([^\/])((www|[^\/\. ]+)\.[\S]+(\b|$|))/gim, '$1<a href="http://$2$3" target="_blank">$2$3</a>');
};
@karmiphuc
karmiphuc / script.js
Last active January 4, 2016 13:49
Test js async
document.getElementById('second').innerHTML = 'And this is Javascript';
@karmiphuc
karmiphuc / sampleHTML5.html
Created January 26, 2014 11:36
HTML5 Template
<html lang="vi">
<head>
<meta charset="UTF-8" />
<title>Test | KarmiPhuc</title>
<!-- đặt CSS ở thẻ head -->
<link...>
</head>
<body>
<!-- HTML here ...-->
<!-- đặt JS trước khi đóng body -->
@karmiphuc
karmiphuc / Notepad-Plus-Plus.tmTheme
Last active August 29, 2015 13:56
My SublimeText 3 setting
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Notepad-Plus-Plus</string>
<key>settings</key>
<array>
<dict>
<key>settings</key>