Skip to content

Instantly share code, notes, and snippets.

@ij96
ij96 / 163-get-lyrics-py.py
Last active May 3, 2025 16:55
Get song info and lyrics from music.163.com by using Python 3
from urllib.request import Request, urlopen
import json
class song:
song_id = 0
name = ''
album = ''
artist = ''
lyrics = ''
tlyrics = ''
@ij96
ij96 / transfer.m
Created January 20, 2018 17:06
transfer function Bode + Nyquist
close all;
num = [0 0 0 0.35];
den = [1 1.5 0.75 0.125];
H = tf(num,den)
figure;
bode(H);
figure;
@ij96
ij96 / re_extractor.py
Created January 29, 2018 15:26
Extracts all regex matches in a file and output to another file
#!/usr/bin/python3.5
import re, sys
SEPARATOR = '\n'
def extract(pattern, in_file_name, out_file_name):
in_file_content = ""
with open(in_file_name, 'r') as in_file:
in_file_content = in_file.read()
@ij96
ij96 / beat_effect.m
Created March 9, 2018 17:37
MATLAB script to demonstrate the beating effect when an analogue signal is sampled
% demonstrate the beating effect when an analogue signal is sampled
% more on: https://en.wikipedia.org/wiki/Beat_(acoustics)
clc; close all;
%//////////////////// parameters //////////////////////////////////////////
samp_freq = 8000; % sampling frequency
input_freq = 3800; % input sine wave frequency
num_of_cycles = 15; % number of input cycles to display on graph
x_accu_reso = 100; % input resolution: number per sample points on input
@ij96
ij96 / compression.cpp
Created June 19, 2018 23:14
An inefficient compression algorithm
#include <iostream>
#include <fstream>
int main() {
std::ifstream is("input.data", std::ios::binary);
std::ofstream os("output.data", std::ios::binary);
char b[2];
ushort x, px, c = 0;
ushort ct = 2; // num. of repeated data to be written out
if(is) {
@ij96
ij96 / arduino_delay_signal.ino
Last active August 8, 2018 15:22
Delay a signal by a fixed time accurately, by using interrupt
// Arduino UNO
// faster digital read and write using register and bit mask
#define FAST_DIGITAL_READ(REG, MASK) (*REG & MASK) != 0;
#define FAST_DIGITAL_WRITE(REG, MASK, VAL) (VAL == LOW) ? (*REG &= ~MASK) : (*REG |= MASK);
// pin definition
#define OUTPUT_PIN 13
#define INTERRUPT_PIN 2
@ij96
ij96 / rename_mp3.sh
Last active November 6, 2022 00:26
Rename MP3 files based on metadata
# rename MP3 files based on metadata (named artist and title)
# copy this script in the same directory as the MP3 files and run
# renamed MP3 are copied to renamed/
mkdir renamed;
for f in *.mp3; do
TITLE=`ffmpeg -i "$f" 2>&1 | grep title | sed "s/ \+title \+: //"`;
ARTIST=`ffmpeg -i "$f" 2>&1 | grep artist | sed "s/ \+artist \+: //"`;
TRACK=`ffmpeg -i "$f" 2>&1 | grep track | sed "s/ \+track \+: //"`;
ZERO_TRACK=$(printf %02d ${TRACK}); # zero-padded track number
import os
os.environ['CUDA_DEVICE_ORDER'] = 'PCI_BUS_ID'
os.environ['CUDA_VISIBLE_DEVICES'] = '0' # -1 = no GPU
import tensorflow as tf
import tensorflow.keras as keras
# versions
print('tf version: {}'.format(tf.__version__))
print('keras version: {}'.format(keras.__version__))
@ij96
ij96 / program_attiny85_via_arduino.md
Created November 17, 2019 19:22
Instruction on how to program ATtiny85 via Arduino

How to: program ATtiny85 via Arduino

Configure Arduino as ISP

  • connect Arduino to the PC.
  • open Arduino IDE.
  • open the ArduinoISP example file (File > Examples > ArduinoISP).
  • note: if using Arduino Mega, modify the following lines from:
#define RESET 10
@ij96
ij96 / 3d_printer_script.gcode
Last active December 28, 2019 22:27
Custom 3D printing scripts for ideaMaker
;;;;;;;;;; start script
G21 ; set unit to mm
G90 ; set to absolute positioning
M82 ; set extruder to absolute mode
M107 ; fans off
G28 X0 Y0; home X and Y axes
G28 Z0 ; home Z axis
G1 Z15 F300 ; move to (0, 0, 15)
G92 E0 ; set new extruder position to 0
G1 F140 E29 ; extrude 29mm of material