Skip to content

Instantly share code, notes, and snippets.

View MAGANER's full-sized avatar
🏠
Working from home

Ian MAGANER

🏠
Working from home
  • Russian Federation
View GitHub Profile
@MAGANER
MAGANER / secret_input.py
Created May 27, 2023 15:10
secret input to hide characters, entered by user.
import msvcrt
import sys
def secret_input(prompt,char=""):
'''get terminal input without showing the input'''
fb = lambda n: int.from_bytes(n,byteorder="big")# lambda to convert bytes into int
#show prompt, then flush buffer to redraw
print(prompt,end="")
sys.stdout.flush()
@MAGANER
MAGANER / concat.h
Created March 16, 2023 04:11
fast std::string concat c++
//originally it was written on
template <class... S>
std::string concat(const S&... strs) {
std::string_view views[]{strs...};
int totalsize = std::accumulate(std::begin(views), std::end(views), 0, [](int count, std::string_view v){return count + v.size();});
std::string result(totalsize, '\0');
int cur_pos = 0;
for(const auto& v : views){
std::copy(v.begin(), v.end(), result.begin() + cur_pos);
@MAGANER
MAGANER / XORcoder.hs
Created December 30, 2022 17:25
haskell module to process XOR encryption/decryption
module Coder(encode,decode) where
import Data.Word
import Data.Char(ord,chr)
import Data.Bits(xor)
import qualified Data.ByteString.Char8 as C
import qualified Data.ByteString as B
tp n ls = takeWhile(not.null) $ map(take n.flip drop ls) [0,n..]
conv_key key = [fromIntegral $ ord x | x <- key]
import Data.Char(digitToInt)
main::IO()
main = print $ sum $ map digitToInt $ show $ product[1..100]
sum1::[Int] -> Int
sum1 seq = sum [x*x | x <- seq]
sum2::[Int] -> Int
sum2 seq =
let s = sum [x | x <- seq]
in s*s
main::IO()
main = print $ sum2 [1..100] - sum1 [1..100]
@MAGANER
MAGANER / task1.hs
Created December 29, 2022 14:48
first task solution from https://projecteuler.net in haskell
{-
#1 task from https://projecteuler.net/archives
Find the sum of all the multiples of 3 or 5 below 1000.
-}
mult::Int -> Bool
mult x = x `mod` 5 == 0 || x `mod` 3 == 0
filter_seq::[Int] -> [Int]
filter_seq seq = [x | x <- seq, mult x ]
@MAGANER
MAGANER / collatz.hs
Last active December 29, 2021 08:50
The Collatz hypothesis
kolc::Integer -> Integer
kolc n | even n = toInteger n `div` 2
kolc n | not $ even n = (n*3)+1
gks'::[Integer] -> [Integer]
gks' xs = xs ++ [kolc $ last xs]
gks::[Integer] -> [Integer]
gks xs | (last xs) == 1 = xs
@MAGANER
MAGANER / gen_ignore.py
Created December 8, 2021 10:36
Little python script to generate .gitignore file for c++ projects.
import os
_all = os.listdir(os.getcwd())
files = list(filter(lambda n: os.path.isfile(n),_all))
def is_cpp(file):
ext = [".cpp",".hpp",".h",".c"]
for e in ext:
if file.endswith(e):
return True
@MAGANER
MAGANER / Matrix.hpp
Last active November 27, 2021 15:49
this is simple and safe matrix for C++
#ifndef MATRIX_H
#define MATRIX_H
#include<variant>
using namespace std;
template<class T>
class Matrix
{
private:
T** matrix;
@MAGANER
MAGANER / concat.py
Created July 9, 2021 11:24
i wanted to concatenate different number of .mp3 files, so this script provides such ability.
import sys
from functools import reduce
def read(file):
with open(file,"rb") as f:
return f.read()
all_data = list(map(read,sys.argv[1:]))
concated = reduce(lambda a,b:a+b,all_data)
concated = concated