Skip to content

Instantly share code, notes, and snippets.

@vKxni
vKxni / tsconfig.json
Created May 14, 2023 10:22
Typegoose tsconfig.json | 2023
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */
/* Projects */
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
@vKxni
vKxni / match.ex
Created January 24, 2023 09:41
Macro matching
defmodule MyMacros do
defmacro match(values) do
quoted_values = Enum.map(values, &quote(unquote(&1)))
quote do
def match(x) do
case x do
#{unquote(quoted_values)} -> true
_ -> false
end
@vKxni
vKxni / multiply-macro.ex
Created January 24, 2023 09:39
Macro Math
defmodule MyMacros do
defmacro multiply(factor) do
quote do
def multiply_by_#{unquote(factor)}(x), do: x * unquote(factor)
end
end
end
# Use the macro
defmodule MyModule do
@vKxni
vKxni / hash.pl
Created January 17, 2023 12:57
Hash files recursively
#!/usr/bin/perl
use Digest::MD5 qw(md5_hex);
# Get all files in the current directory
opendir(DIR, ".") or die $!;
my @files = readdir(DIR);
closedir(DIR);
# Loop through each file
foreach my $file (@files) {
defmodule String do
def unique_capitalization(string) do
string
|> String.graphemes
|> Enum.with_index
|> Enum.map(fn {grapheme, index} ->
if rem(index, 2) == 1, do: String.capitalize(grapheme), else: grapheme
end)
|> Enum.join
end
defmodule Word do
def count(string) do
words = String.split(string, " ")
words = words |> Enum.map(&String.trim/1) |> Enum.map(&String.downcase/1)
words = Enum.filter(words, &(String.length(&1) > 1))
word_counts =
Enum.reduce(words, %{}, fn word, counts ->
@vKxni
vKxni / caesar_ids.cpp
Created December 24, 2022 10:52
Caesar cipher implementation in C++20
#include <iostream>
#include <fstream>
#include <string>
// The number of places to shift the letters in the Caesar cipher
const int SHIFT = 3;
int main() {
std::ofstream out_file("user_ids.txt");
@vKxni
vKxni / three.ex
Created December 23, 2022 20:58
A simple tree
defmodule Pyramid do
def print(n) do
for row <- 1..n do
print_row(row)
end
end
defp print_row(row) do
# Concatenate the asterisks instead of multiplying them
IO.puts(String.duplicate("*", row))
@vKxni
vKxni / bits.erl
Created December 17, 2022 12:00
Random Strong bytes
-module(bits).
-export([gen/0]).
gen() ->
P = crypto:strong_rand_bytes(16),
io:format("~p~n", [P]),
gen().
@vKxni
vKxni / println.ex
Created December 11, 2022 12:43
IO.println() in Elixir
defmodule Koni do
@moduledoc """
Create a file with the following content:
IO.println("Your-text-here")
Then run the following command:
Koni.println("path/to/file")
"""
def read_file(file_path) do