Skip to content

Instantly share code, notes, and snippets.

View antfu's full-sized avatar

Anthony Fu antfu

View GitHub Profile
@antfu
antfu / vertical-align.css
Created August 23, 2016 15:36
[CSS] Vertical align
.element {
position: relative;
top: 50%;
transform: perspective(1px) translateY(-50%);
}
@antfu
antfu / 1-vue-background-image.js
Last active August 24, 2016 01:43
[JS] Vue directive for smooth background-image loading
Vue.directive('background-image',{
update: function(url) {
var el = $(this.el);
el.css('transition','opacity 0.5s ease-in').css('opacity',0);
var img = $('<img>', {
src: url
}).hide().on('load',function() {
$(this).remove();
el.css('background-image', 'url("'+url+'")').css('opacity',1);
}).appendTo(el);
@antfu
antfu / config.py
Created August 24, 2016 13:31
[Python] Simple and Easy-to-use python configurations loader
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
Configuration
Usage:
from config import configs
'''
@antfu
antfu / copydir.py
Created August 25, 2016 01:04
[Python] Copy directories
def copydir(src,dst):
if not os.path.exists(dst):
os.mkdir(dst)
for f in os.listdir(src):
path = pjoin(src,f)
if os.path.isfile(path):
dst_path = os.path.join(dst,f)
# if the files modify time is the same, do not copy
if not os.path.exists(dst_path) or os.path.getmtime(path) != os.path.getmtime(dst_path):
# use 'copy2' to keep file metadate
@antfu
antfu / iteration.js
Created August 25, 2016 07:39
[JS] Array iteration
i = keys.length
while (i--) {
// do something
}
@antfu
antfu / height->width.css
Last active August 25, 2016 14:46
[CSS] Make height same as width
.element:before{
content: "";
display: block;
padding-top: 100%; /* Make height same as width */
}
@antfu
antfu / js-css-html-minifier.py
Last active August 25, 2016 14:47
[Python] Javascript/CSS/HTML Minifier
import codecs
import csscompressor
import jsmin
import htmlmin
def js_minify(src,dst):
with codecs.open(src, 'r', 'utf-8') as src_file:
minified = jsmin.jsmin(src_file.read())
with codecs.open(dst, 'w', 'utf-8') as dst_file:
dst_file.write(minified)
@antfu
antfu / store.js
Last active August 26, 2016 03:10
[JS] Local Storage
/*jshint unused:false */
(function (exports) {
'use strict';
var STORAGE_KEY = 'data';
exports.localStorage = {
fetch: function () {
return JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]');
},
save: function (data) {
localStorage.setItem(STORAGE_KEY, JSON.stringify(data));
@antfu
antfu / Unicode中文和特殊字符的编码范围
Created October 5, 2016 14:25 — forked from shingchi/Unicode中文和特殊字符的编码范围
Unicode中文和特殊字符的编码范围
根据Unicode5.0整理如下:
1)标准CJK文字
http://www.unicode.org/Public/UNIDATA/Unihan.html
2)全角ASCII、全角中英文标点、半宽片假名、半宽平假名、半宽韩文字母:FF00-FFEF
http://www.unicode.org/charts/PDF/UFF00.pdf
3)CJK部首补充:2E80-2EFF
http://www.unicode.org/charts/PDF/U2E80.pdf
@antfu
antfu / remove-steam-uninstall-links-from-windows.bat
Created October 20, 2016 05:20
Remove Steam uninstall links