Skip to content

Instantly share code, notes, and snippets.

@zhenyi2697
zhenyi2697 / gist:6699873
Created September 25, 2013 13:48
Javascript: set cookie and set local item utility
function vboxSetCookie(k,v,expire) {
var exp = (v ? (expire ? expire : new Date(2020,12,24)) : new Date().setDate(new Date().getDate() - 1));
document.cookie = k+"="+v+"; expires="+exp.toGMTString()+"; path=/";
}
function vboxSetLocalDataItem(k,v,nocookies) {
// fall back to normal cookie
if(typeof(Storage)==="undefined") {
@zhenyi2697
zhenyi2697 / gist:6536815
Created September 12, 2013 12:53
Javascript: CKEditor setup for bootstrap
This tool is awesome !!!
config.toolbar = [
{ name: 'document', groups: [ 'mode', 'document', 'doctools' ], items: [ 'Source', '-', 'Print',] },
{ name: 'clipboard', groups: [ 'clipboard', 'undo' ], items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ] },
{ name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ], items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Bl
'/',
{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ], items: [ 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFo
{ name: 'styles', items: [ 'Format', 'Font', 'FontSize' ] },
{ name: 'colors', items: [ 'TextColor', 'BGColor' ] },
@zhenyi2697
zhenyi2697 / gist:6534429
Created September 12, 2013 08:24
JavaScript: TinyMce setup for bootstrap
<script src="./tinymce/js/tinymce/tinymce.min.js"></script>
<!-- Example row of columns -->
<div class="row">
<div class="span12">
<script type="text/javascript">
tinymce.init({
menubar:false,
statusbar: false,
selector: "#edit",
@zhenyi2697
zhenyi2697 / gist:6375048
Created August 29, 2013 07:15
Linux: set cursor speed
defaults write NSGlobalDomain KeyRepeat -int 1 # from 0 to 2, 2 is the fastest
@zhenyi2697
zhenyi2697 / gist:6370333
Created August 28, 2013 19:39
Django: admin chinese error
ALTER TABLE django_admin_log MODIFY COLUMN object_repr VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;
@zhenyi2697
zhenyi2697 / gist:6340878
Created August 26, 2013 12:22
Python: markdown not found error handling
try:
from markdown import markdown
except ImportError:
class MarkdownNotFound(Exception):
def __str__(self):
return "Markdown is not installed!"
raise MarkdownNotFound
@zhenyi2697
zhenyi2697 / gist:6184063
Created August 8, 2013 12:09
Python: fibonacci using yield and list comprehension
def fibonacci(max):
a, b = 0, 1
while a < max:
yield a
a, b = b, a+b
print [x for x in fibonacci(100)]
@zhenyi2697
zhenyi2697 / reg_test.py
Created August 6, 2013 07:27
Python: Use regular expression to test input/string
if not re.search(romanNumeralPattern, s):
raise InvalidRomanNumeralError, 'Invalid Roman numeral: %s' % s
@zhenyi2697
zhenyi2697 / gist:6140687
Created August 2, 2013 15:18
Linux: Show last 10 most used command
history | awk '{CMD[$2]++;count++;} END { for (a in CMD )print CMD[ a ]" " CMD[ a ]/count*100 "% " a }' | grep -v "./" | column -c3 -s " " -t |sort -nr | nl | head -n10
@zhenyi2697
zhenyi2697 / get_mac.php
Created August 2, 2013 08:17
PHP: get mac address from php
<?php
function getMacLinux() {
exec('netstat -ie', $result);
if(is_array($result)) {
$iface = array();
foreach($result as $key => $line) {
if($key > 0) {
$tmp = str_replace(" ", "", substr($line, 0, 10));
if($tmp <> "") {
$macpos = strpos($line, "HWaddr");