Skip to content

Instantly share code, notes, and snippets.

View miracleyoo's full-sized avatar

Miracleyoo miracleyoo

  • University of California San Diego
  • San Diego, USA
  • 13:47 (UTC -07:00)
View GitHub Profile
@miracleyoo
miracleyoo / datetime.py
Created January 17, 2020 03:35
[Datetime frequently-used Format] #python
import datetime
datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
@miracleyoo
miracleyoo / timer_log.py
Last active May 1, 2020 02:06
[Timer and Log Functions] #python
import functools
import time
class Timer(object):
def __init__(self, name=None):
self.name = name
def __enter__(self):
self.t_start = time.time()
@miracleyoo
miracleyoo / read_write_encoding.py
Created December 19, 2019 19:42
[Read Write with Right Encoding] #python #file
import chardet
with open(input_path, 'rb') as f:
s = f.read()
chatest = chardet.detect(s)
# print(chatest)
with open(input_path,"r",encoding=chatest["encoding"]) as f:
lines = f.read()
with open(output_path, "w+", encoding=chatest["encoding"]) as fw:
@miracleyoo
miracleyoo / argparse.py
Created December 19, 2019 19:36
[argparse] #python
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser(
'Please input the file path you want to transfer using --input=""')
# Bool
parser.add_argument(
'--compress',
action='store_true',
@miracleyoo
miracleyoo / twitch-recorder.py
Created December 19, 2019 04:54 — forked from junian/twitch-recorder.py
Record Twitch Streams Automatically in Python
# This code is based on tutorial by slicktechies modified as needed to use oauth token from Twitch.
# You can read more details at: https://www.junian.net/2017/01/how-to-record-twitch-streams.html
# original code is from https://slicktechies.com/how-to-watchrecord-twitch-streams-using-livestreamer/
import requests
import os
import time
import json
import sys
import subprocess
@miracleyoo
miracleyoo / TableUtils.java
Last active December 12, 2019 04:51
[Swing Table Utils] #Java #GUI #Swing
/**
* This table utils provide the function of setting the width of each column of a Java Swing table.
* It can Set one column size, or set the preferred or minimum column size.
* Also, it provide the function that allow us to set different color for a certain cell in table.
* */
package com.miracleyoo.utils;
import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
@miracleyoo
miracleyoo / NoneFrame.java
Last active December 12, 2019 04:50
[Swing None Frame ] #Java #GUI #Swing
/**
* A Frame class which provide a boarder-less Frame.
* Also, drag the window by mouse event is implemented.
* */
package com.miracleyoo.utils;
import java.awt.Color;
import java.awt.Point;
import java.awt.event.*;
@miracleyoo
miracleyoo / BackGroundPanel.java
Last active December 12, 2019 04:50
[Swing Background Panel] #Java #GUI #Swing
/**
* Support custom painting on a panel in the form of
*
* a) images - that can be scaled, tiled or painted at original size
* b) non solid painting - that can be done by using a Paint object
*
* Also, any component added directly to this panel will be made
* non-opaque so that the custom painting can show through.
*/
@miracleyoo
miracleyoo / tree.md
Created December 12, 2019 04:18 — forked from hrldcpr/tree.md
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@miracleyoo
miracleyoo / useful_pandas_snippets.md
Created December 12, 2019 04:15 — forked from bsweger/useful_pandas_snippets.md
Useful Pandas Snippets

Useful Pandas Snippets

A personal diary of DataFrame munging over the years.

Data Types and Conversion

Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)