Skip to content

Instantly share code, notes, and snippets.

View llzes's full-sized avatar
🐰
GitHub, drop your ICE contract now.

Avi llzes

🐰
GitHub, drop your ICE contract now.
View GitHub Profile
@llzes
llzes / byteToHex.js
Created February 11, 2020 19:16
Byte to Hex and Hex to Byte in JavaScript.
const byteToHex = (byte) => {
const key = '0123456789abcdef'
let bytes = new Uint8Array(byte)
let newHex = ''
let currentChar = 0
for (let i=0; i<bytes.length; i++) { // Go over each 8-bit byte
currentChar = (bytes[i] >> 4) // First 4-bits for first hex char
newHex += key[currentChar] // Add first hex char to string
currentChar = (bytes[i] & 15) // Erase first 4-bits, get last 4-bits for second hex char
newHex += key[currentChar] // Add second hex char to string

Keybase proof

I hereby claim:

  • I am llzes on github.
  • I am av1 (https://keybase.io/av1) on keybase.
  • I have a public key whose fingerprint is 31FE DE35 59A1 B2FF 413F 0C9D FD2E C57F 49DA B6B6

To claim this, I am signing this object:

@llzes
llzes / fizzbuzz.py
Created July 8, 2019 19:19
Fizzbuzz with no if-statements and loops
def fizzbuzz(num):
# i, 3, 5, 15, 7, 21, 35, 105, 11, 33, 77, 165, 231, 385, 1155
outcomes = [str(num), "bun", "cheese", "buncheese", "cake", "buncake", "cheesecake", "buncheesecake", "fluff", "bunfluff", "cheesefluff", "buncheesefluff", "cakefluff", "buncakefluff", "cheesecakefluff", "buncheesecakefluff"]
# 0b01 = 1 in binary; &1 = %2, to zero out all bits except for the right most to see if it's a non empty number
divByBun = 1 - ( ( (num%3) | (num%3>>1) ) & (0b01) )
divByCheese = (1 - ( ( (num%5) | (num%5>>1) | num%5>>2 ) & (0b01) ) ) * 2
divByCake = (1- ( ( (num%7) | (num%7>>1) | num%7>>2 ) & (0b01) ) ) * 4
divByFluff = (1- ( ( (num%11) | (num%11>>1) | num%11>>2 | num%11>>3 ) & (0b01) ) ) * 8
i = divByBun ^ divByCheese ^ divByCake ^ divByFluff
return outcomes[i]
@llzes
llzes / base64ToByte.js
Last active March 10, 2024 12:07
Byte to Base64 implementation in JavaScript
const base64ToByte = (base64) => {
const key = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
let newBytes = []
let currentChar = 0
let currentByte = 0
for (let i=0; i<base64.length; i++) { // Go over four 6-bit base64 chars to decode into three 8-bit bytes
currentChar = key.indexOf(base64[i])
if (i%4===0) { // First base64 char
currentByte = (currentChar << 2) // Get the 6-bits from first base64 char
}
@llzes
llzes / keybase.md
Created February 2, 2018 00:53
Verifying new GitHub username @llzes

Keybase proof

I hereby claim:

  • I am llzes on github.
  • I am av1 (https://keybase.io/av1) on keybase.
  • I have a public key whose fingerprint is ADC0 4F30 2230 9853 9EF2 F6BA A975 B74E 7C86 777E

To claim this, I am signing this object:

@llzes
llzes / smallToBigPrimeNumTest.js
Created March 19, 2017 00:55
Returning the prime numbers between the smallest and biggest prime number provided.
/* This should take in whatever small prime
and whatever bigger prime number you want
and return the numbers in-between. */
var smallPrime=638489;
var bigPrime=697399;
function primeNumbers(countTo){
for(var i=smallPrime; i<countTo; i++){
if(countTo%i===0){
return false;
}
### Keybase proof
I hereby claim:
* I am Avizc on github.
* I am av1 (https://keybase.io/av1) on keybase.
* I have a public key whose fingerprint is ADC0 4F30 2230 9853 9EF2 F6BA A975 B74E 7C86 777E
To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am Avizc on github.
  • I am av1 (https://keybase.io/av1) on keybase.
  • I have a public key whose fingerprint is FBA5 58C2 50EF 354A E049 21AA 219C FAF9 1ECB A094

To claim this, I am signing this object: