Skip to content

Instantly share code, notes, and snippets.

@everylittlefox
everylittlefox / file-download-router.js
Created December 3, 2022 10:12
an express router that downloads and caches files.
import express from 'express'
import fs from 'fs'
import http from 'http'
import u from 'url'
import path from 'path'
const downloadRouter = express.Router()
let downloadedFiles = {}
@everylittlefox
everylittlefox / libgen-api.js
Last active December 3, 2022 11:29
An express server that crawls Libary Genesis (https://libgen.rocks) and exposes an endpoint '/search' for searching books, comics, articles and other resources.
import { load } from 'cheerio'
import got from 'got'
import url from 'url'
import express from 'express'
import http from 'http'
import 'express-async-errors'
const app = express()
const validationError = (message) => {
# game has two players who take turns placing either an X or an O on the board.
# game's solved if either the grid fills up or a player wins.
# a player wins if they're able to align their character (X or O) along a vertical,
# horizontal, or diagonal set of cells.
class Player
attr_accessor :character
attr_reader :name
def initialize(name)
def bubble_sort(array)
loop do
swapped = false
for i in (1...array.length)
if array[i-1] > array[i]
array[i-1], array[i] = array[i], array[i-1]
swapped = true
end
end
break unless swapped
def substrings(word, dictionary)
dictionary.reduce(Hash.new(0)) do |substr_count, substr|
idx = 0
while idx < word.length
if word[idx, substr.length] == substr
substr_count[substr] += 1
idx += substr.length
else
idx += 1
end
def is_upcase?(string)
string.upcase == string
end
def caesar_cipher(string, key)
upper = "A".ord
lower = "a".ord
cipher_arr = string.chars.map do |c|
if "a".upto("z").include?(c.downcase)