Skip to content

Instantly share code, notes, and snippets.

View Spaceface16518's full-sized avatar
🏫
Learning 🧠

Amrit Rathie Spaceface16518

🏫
Learning 🧠
View GitHub Profile
@Spaceface16518
Spaceface16518 / config.sh
Created November 6, 2020 06:45
My shared dotfiles tool
#!/bin/sh
# Configure your device with tracked dotfiles
# check if git is installed
if ! command -v git >/dev/null 2>/dev/null; then
echo "git command not found"
echo "$0 depends on git"
exit 1
fi
@Spaceface16518
Spaceface16518 / nodiv.rs
Created September 10, 2020 17:20
Division implemented without division, remainder, or multiplication
pub fn div(mut lhs: u32, mut rhs: u32) -> u32 {
// align the most significant bits
let misalign = if let Some(n) = rhs.leading_zeros().checked_sub(lhs.leading_zeros()) {
n
} else {
return 0;
};
rhs <<= misalign;
let mut quotient = 0;
@Spaceface16518
Spaceface16518 / PalindromeYears.hs
Last active September 20, 2019 00:49
Prints all the palindrome years
isPalindrome :: (Eq a) => [a] -> Bool
isPalindrome xs = xs == reverse xs
isNotPalindrome :: (Eq a) => [a] -> Bool
isNotPalindrome xs = xs /= reverse xs
fmt n
| n < 10 = "0" ++ show n
| otherwise = show n
@Spaceface16518
Spaceface16518 / HeronsArea.hs
Created August 6, 2019 01:13
Haskell implementation of Heron's area of a triangle formula
area :: (Integral a, Floating b) => a -> a -> a -> b
area a b c = (sqrt . fromIntegral) $ s * (s - a) * (s - b) * (s - c)
where s = (a + b + c) `div` 2
@Spaceface16518
Spaceface16518 / referenceAngle.f95
Last active August 4, 2019 21:45
A simple haskell function to find any angle's reference angle in degrees (with fortran function for comparison)
integer function referenceAngle(n)
implicit none
integer, intent(in) :: n
integer :: rem
rem = mod(n, 360)
if (rem < 0) then
stop 1
@Spaceface16518
Spaceface16518 / fibonacci.hs
Created August 3, 2019 22:14
The famous one line list of all fibonacci numbers in Haskell
fibs = 1 : 1 : zipWith (+) fibs (tail fibs)
@Spaceface16518
Spaceface16518 / reverse.md
Last active May 28, 2018 03:22
Reverse Module

reverse.py

This module just reverses a number for example:

2008 -> 8002

24 -> 42

123456789 -> 987654321

@Spaceface16518
Spaceface16518 / RandNum.js
Created January 12, 2018 02:42
A random number module
generateRandNum = (min, max) => {
let randomNumber = Math.round((max - min) * Math.random() + min);
return randomNumber;
}
testConnection = () => {
console.log("Connection confirmed: RandNum")
}
@Spaceface16518
Spaceface16518 / Write.js
Last active January 12, 2018 03:47
Write module
write = function = (text) => {
$("#result").text(text);
console.log("\"" + text + "\" " + "was written on the page");
}
testConnection = () => {
console.log("Connection confirmed: Write")
}
export {write, testConnection}
@Spaceface16518
Spaceface16518 / Loop-based.js
Last active January 7, 2018 06:51
Transpose methods
let keyOffset = KeyOffset(key); // calls an external function
let noteNumber = convertNoteToNumber(note); // calls an external function
for (var i = 0; i < keyOffset; i++) {
if (noteNumber > 10) {
noteNumber = 0;
} else {
noteNumber += 1;
}
}
newNote = convertNumberToNote(noteNumber); // calls an external function