Skip to content

Instantly share code, notes, and snippets.

View DrunkenAlcoholic's full-sized avatar
💭
Drunk

DrunkenAlcoholic DrunkenAlcoholic

💭
Drunk
View GitHub Profile
@DrunkenAlcoholic
DrunkenAlcoholic / gist:1f2abb927572d86d444645279b973b12
Last active December 19, 2024 14:48
Bash Wildcard S&R patcher
#!/bin/bash
#############################
# Colors
#############################
red=$'\e[1;31m'
grnn=$'\e[1;32m'
yel=$'\e[1;33m'
blu=$'\e[1;34m'
cyn=$'\e[1;36m'
@DrunkenAlcoholic
DrunkenAlcoholic / mexicanWave.nim
Last active October 17, 2024 15:04
Mexican Wave [Codewars - Nim]
import std/strutils
proc wave(people: string): seq[string] =
for i, letter in people:
if letter == char(32):
continue
result.add(people[0..pred(i)] & people[i].toUpperAscii & people[succ(i)..^1])
@DrunkenAlcoholic
DrunkenAlcoholic / writePatches.nim
Created October 12, 2024 00:34
Binary Write Patches
import os
type
Patch = tuple
address: int64
data: seq[byte]
let FilePath: string = "/opt/sublime_text/sublime_text"
let Patches: seq[Patch] = @[(address: 0x003F75D9, data: @[0x48, 0xC7, 0xC0, 0x00, 0x00, 0x00, 0x00, 0xC3]),
(address: 0x003E0E7A, data: @[0x90, 0x90, 0x90, 0x90, 0x90]),
@DrunkenAlcoholic
DrunkenAlcoholic / ANSI.md
Created July 29, 2024 14:41 — forked from fnky/ANSI.md
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@DrunkenAlcoholic
DrunkenAlcoholic / sensibo.nim
Last active June 11, 2024 06:40
Sensibo API
## Sensibo, fetches current temperature, humidity
## from users API key and DeviceID
## API documentation found at https://sensibo.github.io
## eventually want to convert https://github.com/Sensibo/sensibo-python-sdk to the Nim language
import std/[httpclient, json]
type
acStates = object
on: bool
@DrunkenAlcoholic
DrunkenAlcoholic / twelve.days.nim
Created May 14, 2024 04:13
Twelve Days [Exercism - Nim]
proc recite*(start: int, stop = -1): string =
let lyrics: array[1..12, string] = ["On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree.",
"On the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree.",
"On the third day of Christmas my true love gave to me: three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.",
"On the fourth day of Christmas my true love gave to me: four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.",
"On the fifth day of Christmas my true love gave to me: five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.",
"On the sixth day of Christmas my true love gave to me: six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens
@DrunkenAlcoholic
DrunkenAlcoholic / n.prime.nim
Created May 14, 2024 04:11
Nth Prime [Exercism - Nim]
import std/math
proc isPrime(number: int): bool=
let squareRoot = int(sqrt(float(number)))
for i in 2..squareRoot+1:
if number mod i == 0: return false
return true
proc prime*(n: int): int =
import strutils, unicode
const Alpha = "abcdefghijklmnopqrstuvwxyz".reversed
proc encode*(s: string, decode: bool = false): string =
var str = s.replace(" ")
for i in 0..<str.len:
if str[i].toLowerAscii in Alpha: result.add(Alpha[ord(str[i].toLowerAscii) - 97])
@DrunkenAlcoholic
DrunkenAlcoholic / collatz.conjecture.nim
Created May 14, 2024 04:08
Collatz Conjecture [Exercism - Nim]
proc steps*(n: int): int =
if n < 1: raise (ref ValueError)()
var Num = n
while Num > 1:
inc(result)
if Num mod 2 == 0:
Num = Num div 2
else:
Num = Num * 3 + 1
@DrunkenAlcoholic
DrunkenAlcoholic / anagram.nim
Created May 14, 2024 04:05
Anagram [Exercism - Nim]
import strutils
proc detectAnagrams*(word: string, candidates: openArray[string]): seq[string] =
for candidate in candidates:
if word.toLowerAscii == candidate.toLowerAscii or word.len != candidate.len : continue
for ch in candidate.toLowerAscii:
if not contains(word.toLowerAscii, ch) or cmp(count(word.toLowerAscii, ch), count(candidate.toLowerAscii, ch)) > 0: break
else:
result.add(candidate)
break