Skip to content

Instantly share code, notes, and snippets.

View abnerfs's full-sized avatar

Abner Santos abnerfs

  • Nubank
  • São Paulo, SP, Brazil
  • 13:22 (UTC -03:00)
View GitHub Profile
#include <sys/socket.h>
#include <string.h>
#include <fcntl.h>
#include <sys/sendfile.h>
#include <unistd.h>
#include <netinet/in.h>
#include <stdio.h>
#include <errno.h> // Add this line to include the errno.h header file
int main()
@abnerfs
abnerfs / spread-array.clj
Created May 14, 2023 23:19
Spread array macro
(defn into-array*
[item]
(if (and (coll? item) (not (map? item)))
(vec item)
[item]))
(defmacro spread-arrays
[x & next]
`(->> (cons ~x [~@next])
(map into-array*)
@abnerfs
abnerfs / chat-gpt-discord-bot.ts
Created March 22, 2023 14:21
Chat GPT discord bot
import { Client, Intents } from 'discord.js';
import { REST } from '@discordjs/rest';
import { Routes } from 'discord-api-types/v9';
import { CommandInteraction, CommandInteractionOptionResolver, GuildMember, Interaction, Message } from 'discord.js';
import yts from 'youtube-search';
import ytdl from 'ytdl-core';
import { AudioPlayerStatus, createAudioResource, createAudioPlayer, joinVoiceChannel, VoiceConnectionStatus } from '@discordjs/voice';
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_VOICE_STATES] });
const token = 'your-bot-token-here';
@abnerfs
abnerfs / youtube-dl-download-mp3
Last active July 30, 2023 01:24
youtube-dl-download-mp3
youtube-dl --extract-audio --audio-format mp3 <video URL>
@abnerfs
abnerfs / invert-binary-tree.lua
Created May 21, 2022 01:00
Invert binary tree in lua
function invertTree(root)
if not root then
return nil
end
invertTree(root.right)
invertTree(root.left)
local temp = root.left
root.left = root.right
@abnerfs
abnerfs / quicksort.lua
Created March 3, 2022 00:02
QuickSort in Lua
--https://stackoverflow.com/a/27028488
function dump(o)
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. dump(v) .. ','
end
return s .. '} '
else
@abnerfs
abnerfs / binary-search.clj
Last active March 14, 2024 02:13
Clojure binary search
(defn binary-search
"Binary search: https://en.wikipedia.org/wiki/Binary_search_algorithm"
([s coll]
(binary-search s coll 0 (-> coll count dec)))
([s coll l r]
(let [middle (-> (+ l r)
(/ 2)
Math/floor
int)
middle-value (nth coll middle)]
youtube-dl -f bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio --merge-output-format mp4 <URL>
@abnerfs
abnerfs / tsconfig.json
Created December 11, 2021 22:28
TypeScript Config
{
"compilerOptions": {
"target": "es2017",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "commonjs",
"rootDir": "./src",
"outDir": "./dist",
"removeComments": true,
"esModuleInterop": true,