Skip to content

Instantly share code, notes, and snippets.

Jinyang Li jinyangustc

Block or report user

Report or block jinyangustc

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View python_cheatsheet.md

How to sort dict...

By value

Return as a list of tuples:

x = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0}
sorted_x = sorted(x.items(), key=lambda kv: kv[1])
#=> [(0, 0), (2, 1), (1, 2), (4, 3), (3, 4)]
View time_range.py
"""
`datetime` is included in the standard library.
time format:
%d: Day of the month as a zero-padded decimal number. 01, 02, ..., 31
%m: Month as a zero-padded decimal number. 01, 02, ..., 12
%Y: Year with century as a decimal number.
%H: Hour (24-hour clock) as a zero-padded decimal number. 00, 01, ..., 23
%M: Minute as a zero-padded decimal number. 00, 01, ..., 59
"""
@jinyangustc
jinyangustc / config2.json
Created Jul 22, 2019 — forked from pmav99/config2.json
Python logging configuration using JSON. If you want an updated example also covering YAML files, check here: https://github.com/pmav99/python-logging-example
View config2.json
{
"logging": {
"version": 1,
"disable_existing_loggers": true,
"formatters": {
"brief": {
"class": "logging.Formatter",
"datefmt": "%I:%M:%S",
"format": "%(levelname)-8s; %(name)-15s; %(message)s"
},
@jinyangustc
jinyangustc / script.pl
Created Jul 21, 2019 — forked from bessarabov/script.pl
Script to generate data shown in post 'At what time of day does famous programmers work? Part 2. Workweek vs Weekend.' — https://ivan.bessarabov.com/blog/famous-programmers-work-time-part-2-workweek-vs-weekend
View script.pl
#!/usr/bin/perl
# This script is made to show graphs with git commit time made on workweek vs weekend
#
# The desription of this script and results of its usage is avaliable at:
# https://ivan.bessarabov.com/blog/famous-programmers-work-time-part-2-workweek-vs-weekend
#
# usage:
#
# git log --author="Sebastian Riedel" --format="%H %ai" | perl script.pl
@jinyangustc
jinyangustc / vimgolf.vimrc
Created Jul 19, 2019 — forked from igrigorik/vimgolf.vimrc
Basic vimrc to level the playing field...
View vimgolf.vimrc
" http://vimdoc.sourceforge.net/htmldoc/starting.html#vimrc
set nocompatible " use vim defaults
set scrolloff=3 " keep 3 lines when scrolling
set ai " set auto-indenting on for programming
set showcmd " display incomplete commands
set nobackup " do not keep a backup file
set number " show line numbers
set ruler " show the current row and column
View logger_config.py
import logging
class TaskIdFilter(logging.Filter):
"""This filter injects task_id into the log."""
def __init__(self, task_id):
super().__init__()
self.task_id = task_id
@jinyangustc
jinyangustc / merlin-sublime-popups.patch
Created Jul 15, 2019 — forked from trishume/merlin-sublime-popups.patch
Patch to add type inference and definition popups to Sublime Text's Merlin plugin
View merlin-sublime-popups.patch
diff --git a/Packages/Merlin/sublime-text-merlin.py b/Packages/Merlin/sublime-text-merlin.py
--- a/Packages/Merlin/sublime-text-merlin.py
+++ b/Packages/Merlin/sublime-text-merlin.py
@@ -248,6 +248,57 @@
else:
opened_view.run_command("insert_code", { "arg": sig })
+class MerlinInfoPopup:
+ """
+ Pop up a menu at a point describing an expression
@jinyangustc
jinyangustc / entropy_gain.py
Created Dec 7, 2018 — forked from iamaziz/entropy_gain.py
Calculate Entropy and Information Gain for Decision Tree Learning
View entropy_gain.py
# -*- coding: utf-8 -*-
# calculating the Entropy and Information Gain for: Learning with Trees
# by: Aziz Alto
# see Information Gain:
# http://www.autonlab.org/tutorials/infogain.html
from __future__ import division
@jinyangustc
jinyangustc / vimrc
Created Aug 28, 2018 — forked from r00k/vimrc
A minimal vimrc for beginners
View vimrc
" A minimal vimrc for new vim users to start with.
"
" Referenced here: http://www.benorenstein.com/blog/your-first-vimrc-should-be-nearly-empty/
" Original Author: Bram Moolenaar <Bram@vim.org>
" Made more minimal by: Ben Orenstein
" Last change: 2012 Jan 20
"
" To use it, copy it to
" for Unix and OS/2: ~/.vimrc
View gif-from-tweet.md

gif-from-tweet

There are so many great GIFs out there and I want to have copies of them. Twitter makes that harder than it should be by converting them to MP4 and not providing access to the source material. To make it easier, I made a bash pipeline that takes a tweet URL and a filename, extracts the MP4 from that tweet and uses ffmpeg to convert back to GIF.

Dependencies

  • ffmpeg
    • macOS: brew install ffmpeg
    • Ubuntu/Debian: apt install ffmpeg
You can’t perform that action at this time.