Skip to content

Instantly share code, notes, and snippets.

View carlcarl's full-sized avatar

Carl Huang carlcarl

View GitHub Profile
@carlcarl
carlcarl / gist:1336347
Created November 3, 2011 12:13
prependChild and insertAfter
function prependChild(o,s)
{
if(s.hasChildNodes())
{
s.insertBefore(o,s.firstChild);
}
else
{
s.appendChild(o);
}
@carlcarl
carlcarl / gist:1995926
Created March 7, 2012 20:33
javascript text selection
<head>
<script type="text/javascript">
function GetSelectedText () {
if (window.getSelection) { // Firefox, Opera, Google Chrome and Safari
var range = window.getSelection ();
alert (range.toString ());
}
else {
if (document.selection.createRange) { // Internet Explorer
@carlcarl
carlcarl / coin.c
Created April 12, 2012 19:16
硬幣組合
#include <stdio.h>
int coin(const int coin, const int value)
{
int i, j;
int array[value + 1];
for(j = 1; j < value + 1; j++)
{
array[j] = 0;
}
@carlcarl
carlcarl / gist:3919264
Created October 19, 2012 16:45
javascript ajax log
console.log = (function(message) {
var original_log = console.log;
return function(message) {
$.post('/log', { message: message });
original_log(message);
}
})();
@carlcarl
carlcarl / gist:3968352
Created October 28, 2012 11:13
python requests with session
from requests import session
payload = {
'action': 'login',
'username': USERNAME,
'password': PASSWORD
}
with session() as c:
c.post('http://example.com/login.php', data=payload)
@carlcarl
carlcarl / jquery_ie.html
Created February 1, 2013 17:47
jquery 2.0 version with IE
<!--[if lt IE 9]>
<script src="jquery-1.9.0.js"></script>
<![endif]-->
<!--[if gte IE 9]><!-->
<script src="jquery-2.0.0.js"></script>
<!--[endif]-->

User

  • Appcleaner
  • B1FreeArchiver (unrar)
  • Battery Health
  • BetterTouchTool
  • CCleaner
  • CyberDuck (ftp)
  • DaisyDisk (Disk capacity analyse)
  • Dropbox
if (!($ = window.jQuery)){ // typeof jQuery=='undefined' works too
script = document.createElement( 'script' );
script.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
script.onload=dosomething;
document.body.appendChild(script);
}
else{
dosomething();
}
@carlcarl
carlcarl / 2013_OSDC_schedule
Created April 17, 2013 10:26
2013 OSDC schedule
4/19
What beginners teach us
OpenStack 101
Percona XtraDB Cluster 入門
我如何停止憂慮並愛上 Non-MVC Web Framework
讓系統千變萬化的作業環境
Game Jam and Open Source
第一次 setup openstack + lxc 就上手
Functional Programming Using Underscore.js
@carlcarl
carlcarl / js_upload_file.html
Created April 25, 2013 06:16
Upload file using javascript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8">
<title>test</title>
</head>
<body>
<form name="form" id="form" action="test.php" method="post" enctype="multipart/form-data">
<label for="file">file</label><input type="file" name="file" id="file" onchange="this.form.submit();"/>
</form>