Skip to content

Instantly share code, notes, and snippets.

@z64
z64 / 1_static_ring_buffer.cr
Last active September 18, 2018 13:54
An optimized fixed size ring buffer implementation in Crystal. Designed for quick in-memory storage and serialization of recent event history in web applications
require "json"
# Optimized implementation of a fixed sized ring buffer that exposes
# a simple and "safe" API of `#push` and `#to_a`. `#push`ing to a full
# buffer erases the oldest member.
#
# ```
# # Create a new buffer of Int32, with size 3
# buffer = StaticRingBuffer(Int32, 3).new
# buffer.push(1)
# Encode a time into a snowflake with the given worker ID
def snowflake(time, worker)
value = time.epoch_ms << 22
value | worker
end
# Decode a snowflake into a named tuple of its components
def decode(snowflake)
{time: Time.epoch_ms(snowflake >> 22), worker: snowflake & 0b1111}
end
module Powerbot
module DiscordEvents
module Spong
extend Discordrb::EventContainer
CHANNELS = [
226941225339584513,
225375815087554563
]
@z64
z64 / scope.cr
Last active June 21, 2017 02:45
@[Flags]
enum Method
None
Get
Post
Put
Patch
Delete
end

Keybase proof

I hereby claim:

  • I am z64 on github.
  • I am z64 (https://keybase.io/z64) on keybase.
  • I have a public key whose fingerprint is E06F 6AC5 00E3 1D33 0DA7 6404 2CD1 AA8E 1137 87ED

To claim this, I am signing this object:

@z64
z64 / example.cr
Last active February 27, 2017 22:11
basic string converter macro for crystal
require "json"
require "yaml"
require "./string_converter"
data = {test: "1", value: "3.5"}
json_data = data.to_json
yaml_data = data.to_yaml
class Data
@z64
z64 / RubyOOP.md
Last active August 4, 2017 02:16
@z64
z64 / DiscordYoutubeBot.rb
Last active July 19, 2018 21:46
Code Snippet for playing youtube videos (as mp3s) in discord using youtube-dl and discordrb
#Install libsodium (python3-nacl and libsodium-dev worked for me), libopus (libopusfile0 and libopus0 worked for me), ffmpeg
#Install https://github.com/rg3/youtube-dl
require 'discordrb'
$isplaying = 0
bot = Discordrb::Commands::CommandBot.new token: token, client_id: clientid, prefix: '.'
bot.command(:play) do |event, songlink|
if $isplaying == 1
event.message.delete
event.respond 'Already playing music'
break
@z64
z64 / pristine.md
Last active September 14, 2016 20:18

Pristine Rings in Powerplay

This is a compiled list of Pristine rings across the galaxy as reported in EDDB, as of the date of this file.

The distance to that power's HQ is listed in parenthesis.