Skip to content

Instantly share code, notes, and snippets.

View LeoDT's full-sized avatar
🈳

LeoDT

🈳
View GitHub Profile
const year = '2019';
Array.from(document.querySelectorAll('.wallet_table_row'))
.filter(tr => {
return (
tr.querySelector('.wht_type div:first-child').textContent === '购买' &&
tr.querySelector('.wht_date').textContent.indexOf(year) !== -1
);
})
.map(tr =>
{
"basics": {
"name": "Cheng Liu",
"label": "Web Developer",
"summary": "A Web Developer who love building websites and webapps",
"email": "leojoy710@gmail.com",
"location": {
"city": "Shanghai",
"countryCode": "CN"
},
@LeoDT
LeoDT / auto_reload.py
Created July 30, 2013 02:52
touch the target file when any file in source directory changed, useful for auto reload apache wsgi.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import time
import optparse
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
@LeoDT
LeoDT / compress
Created May 16, 2013 07:09
compress some dir's css and js
#!/bin/bash
ai_dir=/opt/www/ai
function scandir() {
local cur_dir workdir
workdir=$1
cd ${workdir}
if [ ${workdir} = "/" ]
then
@LeoDT
LeoDT / encrypt
Created May 10, 2013 01:49
php encrypt to hex
function hex2bin($data)
{
return pack("H" . strlen($data), $data);
}
function encrypt($key, $data)
{
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_ECB),MCRYPT_RAND);
return bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_ECB, $iv));
}
@LeoDT
LeoDT / plugins
Created May 7, 2013 07:30
backbone like event map
$.fn.event_map = function(map){
var el = this;
$.each(map, function(k, v){
var event = k.slice(0, k.indexOf(" ")),
selector = k.slice(k.indexOf(" ") + 1, k.length);
if(event && typeof v === "function"){
if(k.indexOf(" ") != -1){
el.on(event, selector, v);
}
@LeoDT
LeoDT / static.py
Created March 11, 2012 04:44
bootle static file merge
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from bottle import Bottle, debug, get, static_file, run
@get("/<filetype>/<filename:path>")
def static(filetype,filename):
merged_file = "./cache/" + filename
@LeoDT
LeoDT / gist:1563455
Created January 5, 2012 02:41
filter html
filter = function(_html) {
var qualifyURL = function(html) {
html = html.replace(/href=\"([^\"]*)\"|href=\'([^\']*)\'/ig, function(url) {
if(url == "" || url.search(/javascript:|vbscript:/) != -1){
return "";
}
try {
return 'href="' + qualify(url.split('href="')[1].split('"')[0]) + '"';
} catch (e) {
return 'href="' + qualify(url.split("href='")[1].split("'")[0]) + '"';
@LeoDT
LeoDT / gist:1350823
Created November 9, 2011 08:20
replaceImgSrc
function replaceImgSrc(id){
var imgs = document.getElementById(id).getElementsByTagName("img");
for(var i=0;i<img.length;i++){
imgs[i].src = qualifyURL(imgs[i].src);
}
}
function qualifyURL(url){
var img = document.createElement('img');
img.src = url;
@LeoDT
LeoDT / hidediv.css
Created October 14, 2011 07:29
hide div without id or class
div{
display:none;
}
div[id],div[class]{
display:block;
}