Skip to content

Instantly share code, notes, and snippets.

View gumblex's full-sized avatar

Dingyuan Wang gumblex

View GitHub Profile
@gumblex
gumblex / progress-all.sh
Created May 3, 2017 03:28
Find out each file position opened by a process
#!/bin/bash
for fd in /proc/$1/fd/*; do
if [ ! -f "$fd" ]; then continue; fi
fdnum=$(basename "$fd")
fdinfo=/proc/$1/fdinfo/$fdnum
name=$(readlink "$fd")
size=$(stat -c "%s" "$name" 2>/dev/null || stat -c "%s" "$fd")
progress=$(grep ^pos "$fdinfo" | awk '{print $2}')
if [ $size -eq "0" ]; then
echo '['$fdnum']' "$name"':' $progress'/'$size
@gumblex
gumblex / urlrename.py
Created February 16, 2017 07:32
Simple script to get rid of url escaped filenames.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import urllib.parse
for f in sys.argv[1:]:
os.rename(f, urllib.parse.unquote_plus(f))
@gumblex
gumblex / ssl.py
Created July 23, 2016 05:32
Patched ssl.py for PyPy3.3 with modern OpenSSL
# Wrapper module for _ssl, providing some additional facilities
# implemented in Python. Written by Bill Janssen.
"""This module provides some more Pythonic support for SSL.
Object types:
SSLSocket -- subtype of socket.socket which does SSL over the socket
Exceptions:
@gumblex
gumblex / copytime.sh
Created May 22, 2016 04:21
Recursively restore file mtime from backup
#!/bin/bash
find . -type f -print0 | while IFS= read -r -d $'\0' filename; do
if [ -f "$1/$filename" ]; then
echo touch -r "$1/$filename" "$filename"
touch -r "$1/$filename" "$filename"
else
echo "$1/$filename" not exist
fi
done
@gumblex
gumblex / rezip.sh
Created May 15, 2016 08:32
Re-zip hacg's encrypted rars
#!/bin/bash
cd "$1"
find . -name "*.rar" -type f -print0 | while IFS= read -r -d $'\0' filename; do
basefn=$(basename "$filename")
basefncut="${basefn%.*}"
unar -p 扶她奶茶 -o /tmp -d "$filename"
7za a -tzip -mx=9 "${filename%.*}".zip /tmp/"$basefncut"/*
rm -rf /tmp/"$basefncut"/
done
@gumblex
gumblex / ansi_mandelbrot.py
Created May 5, 2016 05:57
Mandelbrot ASCII art from PyPy (independent version)
import os
import sys
import colorsys
"""
Black 0;30 Dark Gray 1;30
Blue 0;34 Light Blue 1;34
Green 0;32 Light Green 1;32
Cyan 0;36 Light Cyan 1;36
Red 0;31 Light Red 1;31
@gumblex
gumblex / screenshot.py
Created April 24, 2016 01:26
Volatility 'screenshot' plugin SVG version
# Volatility
# Copyright (C) 2007-2013 Volatility Foundation
# Copyright (C) 2010,2011,2012 Michael Hale Ligh <michael.ligh@mnin.org>
# Copyright (C) 2009 Brendan Dolan-Gavitt
#
# This file is part of Volatility.
#
# Volatility is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
@gumblex
gumblex / WWStarClone.py
Last active May 4, 2016 14:59
Clone of WWStar, an ancient Classical Chinese translator.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
'''
Clone of WWStar, an ancient Classical Chinese translator.
usage: python3 WWStarClone.py [dir]
@gumblex
gumblex / imgfill.py
Last active March 6, 2016 14:48
Fill a canvas with a given image of different sizes.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import random
from PIL import Image
'''
Copyright (c) 2016 gumblex
@gumblex
gumblex / ip.sh
Last active June 4, 2022 21:58
CGI script: Show visitor's IP and User Agent
#!/bin/bash
echo 'Status: 200 OK'
echo 'Content-Type: text/html; charset=utf-8'
echo
echo '<!DOCTYPE html>'
echo '<html><head>'
echo '<meta http-equiv="content-type" content="text/html; charset=UTF-8">'
echo '<meta name="description" content="'"$HTTP_USER_AGENT"'">'
# we use CloudFlare