Skip to content

Instantly share code, notes, and snippets.

@glasslion
glasslion / generic_relations.py
Created August 16, 2013 07:25
Cache the generic relation field of all the objects in the queryset, using larger bulk queries ahead of time. Improved from original by Daniel Roseman: http://blog.roseman.org.uk/2010/02/22/django-patterns-part-4-forwards-generic-relations/ and justinfx's gist cache_generics.py : https://gist.github.com/justinfx/3095246#file-cache_generics-py Su…
'''
Cache the generic relation field of all the objects
in the queryset, using larger bulk queries ahead of time.
Improved from original by Daniel Roseman:
http://blog.roseman.org.uk/2010/02/22/django-patterns-part-4-forwards-generic-relations/
and
justinfx's gist cache_generics.py :
@glasslion
glasslion / django-debug-toolbar-v0.9.4-Python25
Created August 22, 2013 06:24
A patch that make django-debug-toolbar work in Python 2.5
diff --git a/debug_toolbar/panels/sql.py b/debug_toolbar/panels/sql.py
index 18fffdc..a0bfce8 100644
--- a/debug_toolbar/panels/sql.py
+++ b/debug_toolbar/panels/sql.py
@@ -193,8 +193,14 @@ class SQLDebugPanel(DebugPanel):
stacktrace = []
for frame in query['stacktrace']:
params = map(escape, frame[0].rsplit('/', 1) + list(frame[1:]))
+ params_dict = dict((unicode(idx), v) for idx, v in enumerate(params))
try:
@glasslion
glasslion / pyvideo_feedparser
Last active August 29, 2015 13:59
A simple script extract metadata from a Pyvideo category feed url, and print to stdout.
# coding: utf-8
from __future__ import print_function
import feedparser
import sys, codecs
if not sys.stdout.isatty():
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
if __name__ == '__main__':
@glasslion
glasslion / retry_google_sorry.user.js
Last active October 14, 2016 09:18
当 Google 搜索遇到 We're sorry... 时, 自动刷新页面重试 的油猴脚本
// ==UserScript==
// @name Retry Google Sorry
// @description 当 Google 搜索遇到 We're sorry... 时, 自动刷新页面重试, 使用代理访问 Google 时, 常遇到这种现象
// @namespace https://gist.github.com/glasslion
// @author glasslion
// @include http*://ipv4.google.com/sorry/index?*
// @version 1.2
// @run-at document-end
// @grant none
// ==/UserScript==
@glasslion
glasslion / extract_youtube_play_list.js
Last active July 17, 2019 07:11
Extract Youtube playlist links
// 1. jQuerify
// 2. Run in console
links = ""
$('a.ytd-grid-video-renderer').each(function(){
links += 'https://www.youtube.com' + $(this).attr('href') + '\n'
})
// ==UserScript==
// @name Piratebay Helper
// @description
// @namespace https://userscripts.org/users/glasslion
// @include *pirate*
// @license MIT
// @version 0.1
// @require https://code.jquery.com/jquery-2.1.3.min.js
// @grant GM_addStyle
// @grant GM_setClipboard
@glasslion
glasslion / adminLteColors.html
Created March 31, 2017 07:21
Color table for AdminLte
<html>
<head>
<meta charset="utf-8">
<title>AdminLTE 2 Colors</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"`>
<link rel="stylesheet" href="https://almsaeedstudio.com/themes/AdminLTE/dist/css/AdminLTE.min.css">
</head>
<body>
<div class="container">
<table class="table table-bordered">
@glasslion
glasslion / outlook_web_batch_delete.js
Created July 3, 2017 07:11
批量删除outlook 里的邮件
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function deleteMails() {
jQuery('._n_U').click()
await sleep(500);
jQuery('.ms-fcl-np[title="删除(Del)"]').click()
}
@glasslion
glasslion / vtt2text.py
Last active March 23, 2024 20:47
This script convert youtube subtitle file(vtt) to plain text.
"""
Convert YouTube subtitles(vtt) to human readable text.
Download only subtitles from YouTube with youtube-dl:
youtube-dl --skip-download --convert-subs vtt <video_url>
Note that default subtitle format provided by YouTube is ass, which is hard
to process with simple regex. Luckily youtube-dl can convert ass to vtt, which
is easier to process.
@glasslion
glasslion / ClipperHelper.js
Last active April 25, 2021 14:08
Bookmarklet that makes web page clipping easy.
var d = document,
useMine = true,
prevEl;
function AddHandler(orig, mine) {
return function(e) {
if (useMine) mine(e);
else if (orig) orig(e);
};
}