Skip to content

Instantly share code, notes, and snippets.

View khursani8's full-sized avatar
🏠
Working from home

Sani khursani8

🏠
Working from home
View GitHub Profile
# -*- coding: utf-8 -*-
"""PySimpleGUI上でテキスト音声合成するサンプルスクリプト."""
import numpy as np
import pyopenjtalk # テキスト音声合成のライブラリ
import PySimpleGUI as sg # GUI構築のライブラリ
import sounddevice as sd # 録音・再生系のライブラリ
# レイアウトの設定;テキストボックスとボタンを配置
LAYOUT = [
@ejmejm
ejmejm / pytorch_tips_yt_follow.ipynb
Created May 9, 2021 09:14
pytorch_tips_yt_follow.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from vidgear.gears import VideoGear
import numpy as np
import cv2
def center_crop(img, dim):
if img is None:
return None
width, height = img.shape[1], img.shape[0]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vadimkantorov
vadimkantorov / tensorbackeddictarray.py
Last active April 12, 2025 11:09
Tensor-backed immutable string array and list-of-dicts to be used in PyTorch Dataset classes to work around copied shared memory-pages when using Python lists of strings https://github.com/pytorch/pytorch/issues/13246
import math
import typing
import torch
class StringArray:
def __init__(self, strings : typing.List[str], encoding : typing.Literal['ascii', 'utf_32_le'] = 'ascii'):
strings = list(strings)
self.encoding = encoding
self.multiplier = dict(ascii = 1, utf_32_le = 4)[encoding]
# TODO: support varlen encodings: utf-8 and utf-16-le
@nileshtrivedi
nileshtrivedi / home-server.md
Last active June 1, 2024 00:11
Home Server setup: Raspberry PI on Internet via reverse SSH tunnel

Raspberry Pi on Internet via reverse SSH tunnel

HackerNews discussed this with many alternative solutions: https://news.ycombinator.com/item?id=24893615

I already have my own domain name: mydomain.com. I wanted to be able to run some webapps on my Raspberry Pi 4B running perpetually at home in headless mode (just needs 5W power and wireless internet). I wanted to be able to access these apps from public Internet. Dynamic DNS wasn't an option because my ISP blocks all incoming traffic. ngrok would work but the free plan is too restrictive.

I bought a cheap 2GB RAM, 20GB disk VM + a 25GB volume on Hetzner for about 4 EUR/month. Hetzner gave me a static IP for it. I haven't purchased a floating IP yet.

# Now available here: https://github.com/y0ast/pytorch-snippets/tree/main/minimal_cifar
@mblondel
mblondel / check_convex.py
Last active November 4, 2025 16:07
A small script to get numerical evidence that a function is convex
# Authors: Mathieu Blondel, Vlad Niculae
# License: BSD 3 clause
import numpy as np
def _gen_pairs(gen, max_iter, max_inner, random_state, verbose):
rng = np.random.RandomState(random_state)
# if tuple, interpret as randn
@HudsonHuang
HudsonHuang / audio_format.py
Created October 11, 2019 15:21
Convert audio data of PCM16/float32 to byte, and vice versa.
"""Helper functions for working with audio files in NumPy."""
"""some code borrowed from https://github.com/mgeier/python-audio/blob/master/audio-files/utility.py"""
import numpy as np
import contextlib
import librosa
import struct
import soundfile
def float_to_byte(sig):
@stephenroller
stephenroller / mixout.py
Last active February 10, 2023 23:49
Example of mixout on generic modules.
#!/usr/bin/env python3
"""
Example of a generic Mixout implementation. (Lee et al., 2019).
https://arxiv.org/abs/1909.11299
Implementation by Stephen Roller (https://stephenroller.com).
Updated 2020-02-10 to include 1/(1 - p) correction term. Thanks to
Cheolhyoung Lee for making this correction.