Skip to content

Instantly share code, notes, and snippets.

View Xetera's full-sized avatar

Xetera Xetera

View GitHub Profile
@Xetera
Xetera / restic_backup.sh
Created March 15, 2021 18:34
Backing up mongodb with restic to an S3 bucket
#!/usr/bin/env bash
# This backup file is run daily as a cronjob like:
# 0 0 * * * bash ~/backup.sh >> /var/log/restic_backups.log 2>&1
restic_repository="your-s3-repository-url-here"
# There is probably a way to do this conveniently through stdin but I don't know if
# that's more efficient through a file because mongodb does some questionable stuff
# with piping mongodump to stdout vs saving backups to a file
backup_path="/path/to/emit/backup/file"
@Xetera
Xetera / weverse.js
Last active July 25, 2021 19:25
Weverse.io automatic password login flow for scraping posts/images
const forge = require('node-forge')
const fetch = require('node-fetch')
const publicKey = `-----BEGIN RSA PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu/OhimOynajYomJmBsNvQxSDwekunsp986l7s/zMN/8jHXFlTqT79ZOsOwzVdZcKnkWYXwJg4nhIFpaIsPzklQCImp2kfKUJQV3jzw7/Qtq6NrOOh9YBADr+b99SHYcc7E7cDHjGXgWlC5jEI9h80R822wBU0HcbODkAQ3uosvFhSq3gLpxwdimesZofkJ5ZbAmGIMj1GEWAfMGA49mxkv/cDFWry+6FM4mUW6A0301QUg4wK/8n6RrzRj1NUkevZj1smizHeqmBE+0BU5H/fR9HclErx3LMHlVlxSgEEEjNUx3B0bLO0OHppmEb4B3Tk1O3ZsquYyqZyb2lBTbrQwIDAQAB
-----END RSA PUBLIC KEY-----`
const key = forge.pki.publicKeyFromPem(publicKey);
const encryptedPassword = key.encrypt("your-password-here", 'RSA-OAEP')
console.log(encryptedPassword);
@Xetera
Xetera / fix_fonts.sh
Last active June 3, 2021 13:31
Adding emoji support to the netlify build process, used for taking screenshots with puppeteer
#!/usr/bin/env bash
#check if font is installed
fc-match "Noto Color Emoji"
#if not installed install with following line
apt-get install fonts-noto-color-emoji -y
curl -L https://noto-website-2.storage.googleapis.com/pkgs/NotoColorEmoji-unhinted.zip -o NotoColorEmoji.zip
unzip NotoColorEmoji.zip
@Xetera
Xetera / First Discord Command
Created November 4, 2017 10:57
One of the first "working" pieces of code I wrote in python for discord ft. global variables
async def cmd_weather(self, channel, author):
import json
from array import array
import requests
from collections import OrderedDict
from pprint import pprint
api_key = "&APPID=507e30d896f751513350c41899382d89"
city_name_url = "http://api.openweathermap.org/data/2.5/weather?q="
units = "&units=metric"
global general_info
@Xetera
Xetera / nested-find.js
Created March 29, 2021 21:31
Return a nested subdocument inside an array field from a mongodb query
// Aggregates are a powerful mongodb tool that allows us to craft complex queries.
// In this case it helps prevent repetition in a situation where we would have to
// query a document with a filter, then use a duplicate `Array.find` logic to
// extract the subdocument we were already expecting to find in the first place.
// Example person document
{
name: "jason",
pets: [{
type: "dog",
@Xetera
Xetera / tailwind-colors.css
Created October 27, 2020 18:27
Tailwind 2.0 colors as CSS variables for use outside of tailwind
:root {
--rose-50: #fff1f2;
--rose-100: #ffe4e6;
--rose-200: #fecdd3;
--rose-300: #fda4af;
--rose-400: #fb7185;
--rose-500: #f43f5e;
--rose-600: #e11d48;
--rose-700: #be123c;
--rose-800: #9f1239;
@Xetera
Xetera / route_methods.js
Created August 29, 2019 09:03
A helper function that lets you declare multiple methods for the same endpoint in express.js without repeating things
const routeMethods = (router, url) => {
const unwrap = () => router
const makeRoute = method => handler => {
router[method](url, handler);
return routeMethods(router, url)
}
const methods = ['get', 'post', 'put', 'options', 'delete', 'patch', /* as many methods as you need here */]
return methods.reduce((all, method) => ({
...all,
[method]: makeRoute(method)
@Xetera
Xetera / Stack.hs
Created July 26, 2019 02:21
Basic stack implementation in haskell
data Stack a
= Nil
| Stack a (Stack a)
instance Functor Stack where
fmap f s =
case s of
Stack e next ->
Stack (f e) $ fmap f next
Nil -> Nil
@Xetera
Xetera / keybase.md
Created July 21, 2019 00:36
Keybase

Keybase proof

I hereby claim:

  • I am xetera on github.
  • I am xetera (https://keybase.io/xetera) on keybase.
  • I have a public key whose fingerprint is DE0C C5B3 7058 805B 8DD8 E306 7FB1 9FBF D8E5 BBED

To claim this, I am signing this object: