Skip to content

Instantly share code, notes, and snippets.

@naxmefy
naxmefy / create.sh
Created August 11, 2023 06:20
Simple helper for my lab projects
#!/usr/bin/env sh
# check for command - here example with nestjs
# shellcheck disable=SC2039
if ! command -v nest &> /dev/null
then
echo "nest could not be found. install with 'npm install --global @nestjs/cli'"
exit
fi
@naxmefy
naxmefy / wsl2ports.ps1
Created July 19, 2022 07:50
wsl port forwarding
$remoteport = bash.exe -c " hostname -I | awk '{print $1}'"
# $remoteport = bash.exe -c "ifconfig eth0 | grep 'inet '"
$found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
if( $found ){
$remoteport = $matches[0];
} else{
echo "The Script Exited, the ip address of WSL 2 cannot be found";
exit;
}
@naxmefy
naxmefy / English.js
Last active January 2, 2022 21:03
Unity3D Internationalization (I18N)
#pragma strict
public class English {
public static var lang : Hashtable = {
// General
"game_name": "My Awesome Game"
// Menus
, "new_game" : "New Game"
, "save_game" : "Save Game"
@naxmefy
naxmefy / diamond.js
Created May 24, 2021 17:49
print a diamond with n size
const N = parseInt(readline());
console.log("#".repeat(N));
for(var i = 1; i < (N * 2); i+=2){
console.log(" ".repeat((N*2 - i) / 2) + "#".repeat(i));
}
for(var i = N * 2 - 1; i > 0; i-=2){
console.log(" ".repeat((N*2 - i) / 2) + "#".repeat(i));
}
@naxmefy
naxmefy / add-big-numbers.c
Created May 7, 2021 05:41
Adding Big Numbers
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *add(const char *a, const char *b) {
size_t pos_1, pos_2, pos_3, len_3;
unsigned int carry;
pos_1 = strlen(a);
pos_2 = strlen(b);
@naxmefy
naxmefy / n-digits-palindrome.js
Created May 6, 2021 02:07
palindromes with N-Digits
n = parseInt(readline());
n -= 2
result = 9
result *= 10 ** ~~((n + 1) / 2)
console.log(result);
@naxmefy
naxmefy / descandents.rb
Created May 4, 2021 22:30
find descandents
a=gets.chomp
h=gets.to_i.times.flat_map{s,t=gets.split
{t=>[s],s=>[]}}.reduce{|s,n|s.merge(n){|_,v,w|v+w}}
l=->(r){r+r.flat_map{|a|l[h[a]]}}
r=l[h[a]]
puts r[0]?r.sort: :Nobody
# example
# Emesse
@naxmefy
naxmefy / gcd.rb
Last active April 30, 2021 21:05
a and b both dividable by same integer or coprime (gcd)
eval"p %d.gcd(%d)<2"%[*$<]
@naxmefy
naxmefy / unique-prime-factors.rb
Created April 24, 2021 22:53
unique prime factors in range from a to b
require'prime'
gets
$<.map{|s|p (s.to_i..s[/ .+/].to_i).count{|n|n>0&&n.prime_division[1]}}
@naxmefy
naxmefy / conway.py
Created April 22, 2021 23:23
Print n terms of Conways sequence (without leading 0)
n=int(input())
f=[0,1,1]
for i in range(3,n+1):
f.append(f[f[i - 1]] + f[i - f[i - 1]])
print(*f[1:n+1])