Skip to content

Instantly share code, notes, and snippets.

View Xetera's full-sized avatar

Xetera Xetera

View GitHub Profile
@Xetera
Xetera / You Enjoy Shitty Pizzas.md
Last active December 12, 2017 07:10
Here's a quick way of telling if the pizza you enjoy has actual toppings in it. Chances are it doesn't and you're too scared to try anything that tastes anything even slightly different to what you normally eat.
class Pizza {
    constructor(ingredients) {
        this.ingredients = ingredients;
    }
    // is this thing in the pizza a topping?
    isTopping(topping){
        let newPizza = new Pizza(this.ingredients);
        let index = newPizza.ingredients.indexOf(topping);
        if (index === -1)
@Xetera
Xetera / Building.py
Last active December 22, 2017 22:15
Python Teaching Template
import random
class Building:
def __init__(self, world, name, owner, color, _type):
self.name = name
self.owner = owner # Person obj
self.color = color
self.type = _type
self.assign_person(owner)
@Xetera
Xetera / DontLeakYourTokens.ts
Created March 23, 2018 16:43
Small script to give people who leak their discord tokens a heads-up
import {Client, RichEmbed} from 'discord.js'
const client = new Client();
client.login(process.env['BOT_TOKEN']);
function sendEmbed(ownerURL: string, appId: string){
return new RichEmbed()
.setAuthor(`⛔ Yikes, you leaked your token! ⛔`)
.setThumbnail(ownerURL)
.setColor('#ff0000')
@Xetera
Xetera / everwing_hacks.js
Created December 10, 2018 07:13
simple hack to remove all the fun out of some stupid Facebook game
/* 1. press ctrl + shift + i
* 2. go to "Console" and find any log that starts with "###", click on its link
* 3. pretty print the script
* 4. search for "player.x = "
* 5. put a breakpoint on the same line and move your character with your mouse (game is paused now)
* 6. paste in the script
* 7. remove breakpoint, continue game
* 8. dab on the haters but enjoy knowing the fact you're so salty in a Facebook game that you search for hacks
*/
@Xetera
Xetera / collatz.hs
Created December 15, 2018 03:49
basic collatz conjecture in haskell
fromEven num = num `div` 2
fromOdd = (+1) . (*3)
collatz :: Int -> [Int]
collatz num
| num == 1 = [1]
| even num = next fromEven
| odd num = next fromOdd
where next func = num : (collatz $ func num)
@Xetera
Xetera / glob.js
Last active February 12, 2019 06:28
Basic glob function
const partition = (func, array) => array.reduce(([pass, nopass], item) => {
if (func(item)) {
return [[...pass, item], nopass]
}
return [pass, [...nopass, item]]
}, [[], []]);
const glob = async (path, regex) => {
const dirContent = await fsp.readdir(path, {withFileTypes: true})
@Xetera
Xetera / batch.js
Created February 15, 2019 10:40
Processing an array of promises* in batches of X requests at a time
/**
* (*) Due to the eager nature of promises, `items` must be an
* array of promise returning functions and not an array of promises
*/
const batchProcess = (count, items) => {
const chunked = R.splitEvery(count, items);
const process = async ([head, ...tail]) => {
const promises = head.map(func => func());
const results = await Promise.all(promises);
@Xetera
Xetera / asyncMap.js
Created February 17, 2019 11:13
Mapping an array asynchronously with maximum N number of concurrent requests
const parallelMap = (arr, fn, max) => {
const out = [];
const initial = [...Array(max)];
const fired = initial.map(() => Promise.resolve().then(async function cb() {
if (!arr.length) return
const next = arr.shift();
out.push(await fn(next));
return cb();
}));
@Xetera
Xetera / akairo.ts
Created March 11, 2019 01:13
Helper function that makes creating functions with Akairo much less verbose
import { CommandOptions, Command } from "discord-akairo";
interface CreateCommand extends CommandOptions {
/**
* The exec function can be called in 3 different ways, however,
* Typescript doesn't seem to be able to support explicit `this`
* coming from external types, union types or overloads. In order to
* specify the `this` type the signature MUST be directly assigned
* in the interface
*/
@Xetera
Xetera / chunk.js
Created March 24, 2019 06:00
Method that chunks an array of n elements into sub-arrays of max y elements
const chunk = (array, num) => array.reduce((array, current) => {
const last = array[array.length - 1];
const init = array.slice(0, -1);
if (!last) {
return [...init, [current]]
}
if (last.length >= num) {
return [...array, [current]]
}
return [...init, [...last, current]];