Skip to content

Instantly share code, notes, and snippets.

View lotabout's full-sized avatar

Jinzhou Zhang lotabout

View GitHub Profile
@lotabout
lotabout / pod.py
Last active December 6, 2016 09:06
download the wallpaper from bing.com and set it as wallpaper, everyday.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# You can put it into crontab
# * */2 * * * HOME=/home/<your username> DISPLAY=:0 <path to the script>
# it will run every two hours to check for new pictures.
from datetime import datetime
import urllib
import urllib2
@lotabout
lotabout / pod.rb
Last active October 29, 2016 01:58
#!/usr/bin/env ruby
require 'open-uri'
picture_folder = File.expand_path("~/Pictures/pod")
page = open('http://cn.bing.com/', 'User-Agent' => "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0").read
img_url = page.to_s.scan(/g_img={url: \"(.*?)\",/).last.first
download_url = case img_url
when /^\/\//
@lotabout
lotabout / what-forces-layout.md
Created August 10, 2016 03:25 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
@lotabout
lotabout / mutable_closure.rs
Created June 11, 2016 08:46
Rust closure as mutable callback.
use std::thread;
fn do_something<'a>(mut callback: Box<FnMut() + 'a>) {
// check http://stackoverflow.com/questions/35651279/error-closure-may-outlive-the-current-function-but-it-will-not-outlive-it
// about why adding 'a will work
callback();
}
fn main() {
let mut ret = 0;
fn gen_wheel(primes: Vec<u64>) -> Box<std::iter::Iterator<Item = u64>> {
let mul = primes.iter().fold(1, |acc, x| acc * x);
let stroke_left: Vec<_>= (2..(mul+1))
.filter(|x| primes.iter().all(|&y| x % y != 0))
.collect();
let front_wheel: Vec<_> = vec![0].iter().chain(primes.iter())
.zip(primes.iter().chain(stroke_left.iter().take(1)))
.map(|(&x, &y)| y - x)
@lotabout
lotabout / google-translate.py
Last active November 11, 2020 13:07
Translate texts
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# translate utility that utilize google translator, support python2 & python3
# Note that the order or arguments in the URL matters.
try:
from urllib import urlencode
except:
from urllib.parse import urlencode
@lotabout
lotabout / crawler_dribbble.py
Created January 17, 2016 14:08
A crawler for dribbble.com
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
import re
import os
import json
import logging
import traceback
@lotabout
lotabout / extract_color.py
Created January 15, 2016 10:24
Extract the main color(and usage) used by an image, like color thief but in python.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys, argparse
from PIL import Image
from PIL.ImageDraw import Draw
import sys
def to_hash(color):
@lotabout
lotabout / colors.sh
Last active January 15, 2016 09:47 — forked from cyrilis/colors.sh
A ImageMagick Script Can Generate Color Palettes JSON Format.Usage: ./colors.sh IMAGE-PATH COLOR-NUMBERS eg: ./colors.sh /Users/Cyril/Downloads/photo2.jpg 10
dir="." #Set the default temp dir
tmpA1="$dir/spectrumhist_1_$$.png"
tmpB1="$dir/spectrumhist_1_$$.cache"
trap "rm -f $tmpA1 $tmpB1; exit 0" 0 #remove temp files
trap "rm -f $tmpA1 $tmpB1; exit 1" 1 2 3 15 #remove temp files
if [ $# -eq 2 ]
then
colors=$2
else
colors=8
@lotabout
lotabout / douban_star.py
Last active January 14, 2016 09:15
get a list of douban starred songs
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import requests
from PIL import Image
import io
import pickle
import os
import json
import time