Skip to content

Instantly share code, notes, and snippets.

View VehpuS's full-sized avatar
🦔

Moshe Jonathan Gordon Radian VehpuS

🦔
View GitHub Profile
@VehpuS
VehpuS / hackernewsGetUserUpvotesDevConsole.js
Last active November 30, 2022 13:27
Scraping personal YCombinator hackernews upvotes from the developer console after login (running in dev console adds the relevant cookie info). Can easily be adapted to an independent scraper / work for more than just the URL
/**
* Get a list of all upvotes urls for a user from a single page
* @param {string} user - The logged in username (you won't be able to get a response for another user)
* @param {number} pageNum - The page of upvotes to query
* @returns {Promise<string[]>} a list of upvoted URLs from the page
*/
const queryUserUpvotesByPage = async (user, pageNum) => {
const req = await fetch(`https://news.ycombinator.com/upvoted?id=${user}&p=${pageNum}`);
const text = await test.text();
return Array.from(text.matchAll(/titleline.*?a href\="(.*?)"/g)).map(([t, url]) => url);
@VehpuS
VehpuS / run_os_cmd.py
Last active April 21, 2024 11:07
Run bash command from python
import subprocess
import sys
def run_os_cmd(
cmd: str, # Command to run
interactive_write: bool=True, # Should the command print as it's running
):
print(f"Running '{cmd}'")
cmd_proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True )
@VehpuS
VehpuS / birthday.sh
Created October 27, 2022 13:06
Birthday wishes in bash
#!/bin/bash
let x=0;until ((x==120)); do let x+=1;echo $x;done
@VehpuS
VehpuS / range_from_slice.py
Last active April 21, 2024 11:07
Given a python slice object and a given length, return a range representing the indices that should be returned for that slice for a collection of that length (useful for implementing __getitem__ for slice as index)
def range_from_slice_overcomplicated(slc: slice, length: int) -> range:
step = 1 if slc.step is None else slc.step
assert step != 0, "slice step cannot be zero"
default_start = 0 if step > 0 else length - 1
default_end = length if step > 0 else 0
return range(
default_start if slc.start is None else (length + slc.start) if slc.start < 0 else slc.start,
default_end if slc.stop is None else max(-1, (length + slc.stop)) if slc.stop < 0 else min(slc.stop, length),
step
)
@VehpuS
VehpuS / singing-synthesis.ipynb
Created August 6, 2022 18:13
singing-synthesis.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@VehpuS
VehpuS / accessing-datasets-rasterio.md
Created June 8, 2022 08:35
Accessing datasets located in buffers using MemoryFile and ZipMemoryFile (based on https://github.com/rasterio/rasterio/issues/977)

Rasterio has different ways to access datasets located on disk or at network addresses and datasets located in memory buffers. This document explains the former once again and then introduces the latter for the first time.

Accessing datasets on your filesystem

To access datasets on disk, give a filesystem path to rasterio.open().

import rasterio

# Open a dataset located in a local file.
with rasterio.open('data/RGB.byte.tif') as dataset:
@VehpuS
VehpuS / downsample-multiband-arr.py
Created June 2, 2022 09:49
downsample a multiband image represented as a 3d numpy array (bands, height, width)
MASKED_VAL = -1 # Will depend on the band data (in my case it was always positive)
width = im.shape[-1]
height = im.shape[-2]
b = math.ceil(max(width, height)/factor)
dest_dim = b * factor
width_pad = dest_dim - width
height_pad = dest_dim - height
@VehpuS
VehpuS / muse-v1-sdk-documentation.html
Created May 19, 2022 20:32
After luckily finding a wayback version of the Muse V1 SDK (which can be accessed by interfacing with the muse-io executable - accessible here https://github.com/VehpuS/muse_tools) - I'm copying the data documentation for future users: https://web.archive.org/web/20181105231756/http://developer.choosemuse.com/tools/available-data#Concentration
<html>
<head>
</head>
<body>
<div class="toc-content">
<p class="large">This is a list of all the data available from MuseIO. For the data available from LibMuse, please see the API Reference for your platform.</p>
<div class="admonition-note-weak">NOTE: Different data parameters like sampling rate, resolution, and more can be configured using <a title="Headband Configuration Presets" href="https://web.archive.org/web/20181105231756/http://dev.choosemuse.com/hardware-firmware/headband-configuration-presets">preset commands</a> that are sent when a connection to Muse is established.</div>
<h2><span id="EEG_Data"><b>EEG Data</b></span></h2>
<div class="toc-step-content">
@VehpuS
VehpuS / git-crypt.md
Created May 3, 2022 17:24
Git Crypt HOWTO

What is git-crypt

In short, git-crypt is a tool that allows you to encrypt and decrypt files with GPG keys in the background of Git commands. Once the tool is properly configured, the files are encrypted on push to and decrypted when fetched from the remote server.

NOTE: git-crypt is not a super secure encryption, and does not replace the need to protect the repo behind 2FA. It's use is to allow us to share code level data that should not be saved with our codebase (i.e. external credentials) but that we still wish to share with the team.

Setup

Based on this guide.

Git-crypt and GPG installation

@VehpuS
VehpuS / mod-a-b.js
Created March 10, 2022 17:13
Calculating modulo with other arithmetic functions (thanks to https://stackoverflow.com/questions/35155598/unable-to-use-in-glsl for the idea)
// neither recursion nor looping is necessary to compute a mod b. That's easily done by a - (b * floor(a/b)).
const mod = (a, b) => a - (b * floor(a/b))
// Simple, but powerful when running on platforms that lack the function but have the floor function (i.e. GLSL for deck.gl)
// Thanks to https://stackoverflow.com/questions/35155598/unable-to-use-in-glsl for the idea