Skip to content

Instantly share code, notes, and snippets.

View teidesu's full-sized avatar
🌸
bark bark woof woof idrk

alina 🌸🦴 teidesu

🌸
bark bark woof woof idrk
View GitHub Profile
@teidesu
teidesu / linked-list.js
Created June 22, 2021 13:11
Linked list for JavaScript without using native arrays. Pretty untested, but kind of works
export class LinkedList {
constructor () {
this._first = null
this._last = null
this.length = 0
}
push (item) {
let value = {
prev: null,
@teidesu
teidesu / exloader.js
Created June 22, 2021 13:11
Simple script to download galleries from exhentai.org w/out GPs, H@H or torrents.
#!/usr/bin/env node
/*
Simple script to download galleries from exhentai.org w/out GPs, H@H or torrents
Requires node >= 10 to run (uses fs.promises)
Dependencies:
yarn add cheerio node-fetch mime-types
# or
npm install cheerio node-fetch mime-types
@teidesu
teidesu / create-sse.ts
Created June 22, 2021 13:11
simple sse for koa
import { Context } from 'koa'
function isPojo (obj: any): boolean {
return obj && typeof obj === 'object' && obj.constructor === Object
}
export interface SseController {
emit (options?: SseEmitOptions): void
close (): void
@teidesu
teidesu / bencode.js
Created June 22, 2021 13:11
JavaScript BEncode implementation
// This file is licensed under LGPLv3
// (c) teidesu 2020
class Decoder {
pos = 0
constructor (str) {
this.str = str
}
decode () {
@teidesu
teidesu / base32.js
Created June 22, 2021 13:11
JavaScript Base32 implementation
// This file is licensed under LGPLv3
// (c) teidesu 2020
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'
const padLength = [0, 1, 3, 4, 6]
const padChar = '='
function encode (buf) {
let arr = [...buf]
let len = arr.length
let ret = ''
@teidesu
teidesu / torrent-to-magnet.js
Created June 22, 2021 13:11
Simple NodeJS function to convert .torrent files to magnet URIs
// This file is licensed under LGPLv3
// (c) teidesu 2020
const qs = require('querystring')
const crypto = require('crypto')
// https://gist.github.com/teidesu/a1eadf71ffd88166415e2ea8b94d3f3b
const bencode = require('./bencode')
function convert (file) {
const data = bencode.decode(f)
@teidesu
teidesu / success-race.js
Created June 22, 2021 13:11
Promise.race but error-tolerant
/**
* Similar to Promise.race(), but resolves once one of the promises
* resolve to a successful value and didn't throw error.
* A promise result is considered `successful` when
* check(result) resolves to a truthy value.
*
* When all promises resulted with unsuccessful values, `null` is returned,
* otherwise result of first successful one is returned
*
@teidesu
teidesu / KawaiiCircularProgress.java
Created June 22, 2021 13:12
Kawaii material circular progress for android. preview: https://imgur.com/49Qs6GT
package desu.player.views;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Interpolator;
@teidesu
teidesu / drklo-emoji-ripper.js
Created June 22, 2021 13:12
Utility to rip emojis and generate sprite sheets and meta information for them.
/**
* Emoji sprite and data generator.
*
* Data is taken from frankerfacez.com and name->char index is generated.
*
* Sprite generator works by parsing some of the code in DrKLO/Telegram (Telegram for Android)
* and downloading emoji files contained there, while generating code and sprite.
*
* Can easily be modified to generate JSON instead of CSS or to download from some other source.
* Can also be easily ported to TypeScript
@teidesu
teidesu / prefixed-localstorage.js
Last active September 23, 2022 12:18
Proxy for localStorage that prefixes all keys.
const prefix = 'prefix_'
const rawLS = window.localStorage
const wrappedLS = new Proxy(rawLS, {
get(target, prop, receiver) {
if (typeof target[prop] === 'function') {
return function(key, value) {
return target[prop](prefix + key, value)
}
}