Standard escape codes are prefixed with Escape
:
- Ctrl-Key:
^[
- Octal:
\033
- Unicode:
\u001b
- Hexadecimal:
\x1B
- Decimal:
27
#!/bin/bash | |
############################# | |
# Colors | |
############################# | |
red=$'\e[1;31m' | |
grnn=$'\e[1;32m' | |
yel=$'\e[1;33m' | |
blu=$'\e[1;34m' | |
cyn=$'\e[1;36m' |
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]) |
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]), |
## 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 |
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 |
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]) |
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 |
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 |