Skip to content

Instantly share code, notes, and snippets.

View watzon's full-sized avatar
👀
Looking for work

Chris Watson watzon

👀
Looking for work
View GitHub Profile
require "file"
require "telegram_bot"
require "./definebot/*"
TOKEN = File.read(File.join(__DIR__, "..", ".secret-token"))
module Definebot
class Bot < TelegramBot::Bot
include TelegramBot::CmdHandler
require "json"
module Types
class Result
JSON.mapping(
metadata: ResultMetadata,
results: Array(Word),
)
end
@watzon
watzon / qs.nim
Last active October 26, 2017 15:46
import json, strutils
proc toQueryString*(json: JsonNode): string =
if json == nil: return ""
var parts: seq[string] = @[]
for key, val in json:
if val.kind != JNull:
if val.kind == JString:
parts.add(key & "=" & val.getStr().encodeUrl())
else:
@watzon
watzon / multisize.rb
Created November 11, 2017 09:30
Resize an image to multiple sizes
#!/usr/bin/env ruby
require 'optparse'
require 'fileutils'
require 'mini_magick'
require 'pp'
options = {
output: '.',
format: '%n%-%s%'
@watzon
watzon / rtl8812au.sh
Created December 29, 2017 07:38
Install rtl8812au driver arch
sudo pacman -S base-devel linux-headers
git clone https://github.com/gnab/rtl8812au.git
cd rtl8812au
make
sudo cp 8812au.ko /lib/modules/$(uname -r)/kernel/drivers/net/wireless
sudo depmod -a
router.get("/", async (req, res) => {
const texts = await TextBlock.find({})
const others = await otherModels.find({})
res.render("adminSite/intro", { texts, others });
});
import std.stdio;
import std.array : split;
import vibe.core.net;
import vibe.stream.tls;
void main()
{
auto addr = "149.154.167.40:443";
auto addrParts = this.addr.split(":");
writeln(addrParts);
@watzon
watzon / input-buffer.js
Created February 5, 2018 05:24
Simple input buffer implementation
const KeyCodeMap = {
backspace: 8,
tab: 9,
return: 13,
left_arrow: 37,
up_arrow: 38,
right_arrow: 39,
down_arrow: 40,
insert: 45,
delete: 46
@watzon
watzon / equalize.cr
Last active March 9, 2024 17:57
Crystal language snippets
# Creates a `#==` method for a class or module.
# Parameters:
# args [Array(Tuple(Symbol, Symbol))] A list of properties to
# use for comparison. The first will be for a method/variable
# in the current class or module, the second will apply to the
# other.
# other_class [Class] The class to compare this one with
# strict [Bool] Set to false to compare with parent classes too
macro equalize(*args, other_class = nil, strict = true)
{{ other_class = other_class ? other_class.id : @type.id }}
@watzon
watzon / media_finder.cr
Created May 11, 2019 11:35
Little script that searches for media using Crystal
class MediaFinder
alias FileInfo = NamedTuple(name: String, directory: String, size: UInt64)
DEFAULT_MEDIA_TYPES = {
images: ["jpg", "jpeg", "gif", "png", "exif", "tiff", "bmp"],
videos: ["webm", "mkv", "flv", "vob", "ogv", "ogg", "gifv", "mng", "avi", "mts", "m2ts", "mov", "qt", "wmv", "mp4", "m4p", "mpg", "mpeg", "m4v", "3gp", "3g2"],
audios: ["aa", "aac", "aax", "aiff", "flac", "m4a", "m4p", "mp3", "ogg", "sln", "wav", "wma"]
}