Skip to content

Instantly share code, notes, and snippets.

View wanghaisheng's full-sized avatar
🏠
Both my parents went to hospital, that sucks for such a 40 years old bachelor

HeisenBerg? wanghaisheng

🏠
Both my parents went to hospital, that sucks for such a 40 years old bachelor
View GitHub Profile
i
me
my
myself
we
our
ours
ourselves
you
your
@wanghaisheng
wanghaisheng / alexa.js
Created June 28, 2024 05:14 — forked from aowongster/alexa.js
Getting the Alexa top 1 million sites directly from the server, unzipping it, parsing the csv and getting each line as an array. Now with majestic
var request = require('request');
var unzip = require('unzip');
var csv2 = require('csv2');
const alexa = 'http://s3.amazonaws.com/alexa-static/top-1m.csv.zip'
const majestic = 'http://downloads.majesticseo.com/majestic_million.csv'
const sources = [majestic];
const zSources = [alexa];
@wanghaisheng
wanghaisheng / 01-mac-profiling.md
Created December 18, 2023 11:18 — forked from loderunner/01-mac-profiling.md
Profiling an application in Mac OS X

Profiling an application in Mac OS X

Finding which process to profile

If your system is running slowly, perhaps a process is using too much CPU time and won't let other processes run smoothly. To find out which processes are taking up a lot of CPU time, you can use Apple's Activity Monitor.

The CPU pane shows how processes are affecting CPU (processor) activity:

@wanghaisheng
wanghaisheng / custom-log-filtering-and-formatting.py
Created October 28, 2023 15:14 — forked from acdha/custom-log-filtering-and-formatting.py
Example of how to filter or apply custom formatting using Python's logging library
#!/usr/bin/env python
# encoding: utf-8
from pprint import pformat, pprint
import logging
class PasswordMaskingFilter(logging.Filter):
"""Demonstrate how to filter sensitive data:"""
@wanghaisheng
wanghaisheng / autotranslate_hardsubs.py
Created July 15, 2023 05:06 — forked from kumorikuma/autotranslate_hardsubs.py
Takes as input a video with hardsubs, and will generate translated softsubs in the target language
# Requirements:
# - ImageMagick binary
# - Windows.Media.Ocr.Cli binary
# - VideoSubFinder binary
#
# Official GCloud Translate Setup:
# First 500k characters / mo is free: https://cloud.google.com/translate/pricing
# Install Python Module: pip install google-cloud-translate
# Setup Google Cloud account and billing information: https://cloud.google.com/
# Make a new project and enable "Cloud Translation API": https://console.cloud.google.com/apis/dashboard
@wanghaisheng
wanghaisheng / ffmpeg.md
Created May 18, 2022 08:00 — forked from protrolium/ffmpeg.md
ffmpeg guide

ffmpeg

Converting Audio into Different Formats / Sample Rates

Minimal example: transcode from MP3 to WMA:
ffmpeg -i input.mp3 output.wma

You can get the list of supported formats with:
ffmpeg -formats

You can get the list of installed codecs with:

@wanghaisheng
wanghaisheng / build_flask_.sh
Created May 8, 2022 12:39 — forked from mrf345/build_flask_.sh
Building one-file executable for Python Flask using Pyinstaller
#!/bin/bash
pyinstaller -F -w \
--hidden-import='email.mime.multipart' \
--hidden-import='email.mime.message' \
--hidden-import='email.mime.text' \
--hidden-import='email.mime.image' \
--hidden-import='email.mime.audio' \
--hidden-import='sqlalchemy.sql.default_comparator' \
--hidden-import='jinja2' \
main.py
@wanghaisheng
wanghaisheng / compress_video.py
Created April 18, 2022 05:23 — forked from ESWZY/compress_video.py
An example Python code for compressing video file to target size.
import os
import ffmpeg
def compress_video(video_full_path, size_upper_bound, two_pass=True, filename_suffix='1'):
"""
Compress video file to max-supported size.
:param video_full_path: the video you want to compress.
:param size_upper_bound: Max video size in KB.
:param two_pass: Set to True to enable two-pass calculation.
:param filename_suffix: Add a suffix for new video.
@wanghaisheng
wanghaisheng / gist:49682cc434e99f0e4c28ed1bee355d0f
Created March 8, 2022 02:54 — forked from eviltester/gist:7beef92896fdd8b638656f996fac38c0
Convert videos into subtitled sections using ffmpeg
# Create a new caption file
~~~~~~~~
ffmpeg -i captions.srt captions.ass
~~~~~~~~
# Add subtitles to main video without changing it
~~~~~~~~
ffmpeg -i video.mp4 -vf "subtitles=captions.ass:force_style='OutlineColour=&H80000000,BorderStyle=4,Outline=1,Shadow=0,MarginV=20'" subtitled-video.mp4
@wanghaisheng
wanghaisheng / ffmpeg-watermark.md
Created December 7, 2021 11:41 — forked from bennylope/ffmpeg-watermark.md
FFmpeg add a watermark to video

How to Add a Watermark to Video

FFMPEG filters provide a powerful way to programmatically enhance or alter videos, and it’s fairly simple to add a watermark to a video using the overlay filter. The easiest way to install ffmpeg is to download a pre-built binary for your specific platform. Then you don’t have to worry about including and installing all the right dependencies and codecs you will be using.

Once you have ffmpeg installed, adding a watermark is as easy as passing your existing source through an overlay filter like so:

ffmpeg -i test.mp4 -i watermark.png -filter_complex "overlay=10:10" test1.mp4

Basically, we’re passing in the original video, and an overlay image as inputs, then passing it through the filter, and saving the output as test1.mp4.