Skip to content

Instantly share code, notes, and snippets.

View mentix02's full-sized avatar
💻
coding away

Manan mentix02

💻
coding away
View GitHub Profile
@mentix02
mentix02 / primelib.cpp
Last active May 22, 2020 17:36
A tutorial for the shipyard testing library.
#include <cmath>
#include <vector>
bool is_prime(const uint32_t n)
{
if ((n & 1) == 0 && n != 2)
return false;
for (uint32_t i = 3; i < std::sqrt(n) + 1; i += 2)
if (n % i == 0)
return false;
@mentix02
mentix02 / genTest.py
Created March 30, 2020 09:45
Go concurrent linear search with Python verification and test generation
import random
if __name__ == '__main__':
nums = [str(random.randint(0, 100000)) for _ in range(100)]
toFind = random.choice(nums)
ans = open('ans.txt', 'w+')
ans.write(str(nums.index(toFind)) + '\n')
ans.close()
print(toFind + ' ' + ' '.join(nums))
@mentix02
mentix02 / git-wc.sh
Created March 18, 2020 13:02
Counts the number of lines of code in a git project except the LICENSE and .gitignore file.
python2 -c "print(`git ls-files | xargs wc -l | grep '\d total' | egrep -o -e '\d+'` - `wc -l LICENSE | egrep -oe '\d+'` - `wc -l .gitignore | egrep -oe '\d+'`)"
@mentix02
mentix02 / index.html
Created March 9, 2020 03:03
A simple chat app.
<!doctype html>
<html>
<head>
<title>Socket.IO chat</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font: 13px Helvetica, Arial; }
form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; }
form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; }
@mentix02
mentix02 / newton.py
Last active March 5, 2020 09:19
Newton's Method implemented in Python
def newton(x0, f, f_, n = 1, r=7):
for i in range(n):
xi = x0 - (f(x0) / f_(x0))
print(f'x{i+1} =', round(xi, r))
x0 = xi
"""
Works for arbitrarily precise floating points.
Usage - calculating √169 (13).
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mentix02
mentix02 / spongebob.py
Created November 3, 2019 22:13
Generates spongebob meme text.
#!/usr/bin/env python3
"""
About -
=======
Generates a randomly upper/lowercased
text from a given input. For example -
Input : Hello World
Output : hEllO wORld
Input : Spam and Eggs
@mentix02
mentix02 / get_file_name_funcs.py
Created August 17, 2019 07:57
gets file name from a path
import pathlib
def get_file_name(path):
return path.split('/')[-1]
def get_file_name_efficient(path):
return path[path.rfind('/')+1:]
path = '/home/name/file.txt'
@mentix02
mentix02 / find_linux_virtualenvs.sh
Last active October 19, 2019 00:00
This is probably the most complex command I've ever crafted to find the virtual enviornments directory in the user's home directory and activate if an enviornment with the same name as the current directory is found (or fail if not found).
source `find /home/$USER -maxdepth 2 -type d -name '.*' 2>/dev/null | grep virtualenv | head -1`/${PWD##*/}/bin/activate
@mentix02
mentix02 / rme.py
Created April 4, 2019 18:53
removes all file in current directory except for the ones mentioned - hence the name - rm EXCEPT
#!/usr/bin/env python3
import os
import sys
NAME = 'rme'
USAGE = 'usage: {} [FILE]...'.format(NAME)
args = sys.argv # simply because I don't like 'argument vector'
if len(args) == 1: