Skip to content

Instantly share code, notes, and snippets.

View kharioki's full-sized avatar
🤘
I'm burdened with glorious purpose

Tony Kharioki kharioki

🤘
I'm burdened with glorious purpose
View GitHub Profile
@kharioki
kharioki / RethinkDB.md
Last active September 17, 2021 16:31
A RethinkDB cheatsheet.

RethinkDB Cheat Sheet

Create database

r.dbCreate('mydb')

List databases

@kharioki
kharioki / contracts...MyContract.sol
Created August 26, 2021 01:55
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.4+commit.c7e474f2.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract MyContract {
string value;
function get() public view returns (string memory) {
return value;
}
@kharioki
kharioki / countries.js
Created August 15, 2021 09:20
All countries listed with their flags, phone dial-code, e.tc.
export const Countries = [
{ ru:"Афганистан",lt:"Afganistanas",tr:"Afganistan", en: 'Afghanistan', flag: '🇦🇫', code: 'AF', dialCode: '+93', mask: '999 999 9999' },
{ ru:"Аландские острова",lt:"Alandų salos",tr:"Aland adaları", en: 'Åland Islands', flag: '🇦🇽', code: 'AX', dialCode: '+358', mask: '999 9999999' },
{ ru:"Албания",lt:"Albanija",tr:"Arnavutluk", en: 'Albania',flag: '🇦🇱',code: 'AL', dialCode: '+355', mask: '999 999 9999' },
{ ru:"Алжир",lt:"Alžyras",tr:"Cezayir", en: 'Algeria',flag: '🇩🇿',code: 'DZ', dialCode: '+213', mask: '9999 99 99 99' },
{ ru:"американское Самоа",lt:"Amerikos Samoa",tr:"Amerikan Samoası", en: 'American Samoa',flag: '🇦🇸',code: 'AS', dialCode: '+1684', mask: '(999) 999-9999' },
{ ru:"андорра",lt:"Andora",tr:"Andorra", en: 'Andorra',flag: '🇦🇩',code: 'AD', dialCode: '+376', mask: '999 999' },
{ ru:"Ангола",lt:"Angoloje",tr:"Angora", en: 'Angola',flag: '🇦🇴',code: 'AO', dialCode: '+244', mask: '999 999 999' },
{ ru:"Ангилья",lt:"Angilija",tr:"Anguilla",
@kharioki
kharioki / getHitProbability.js
Created July 6, 2021 08:43
Calculation hit probability in battleship game in 2d array
function getHitProbability(R, C, G) {
// Write your code here
let empty = 0;
let filled = 0;
let tot = R*C
for(let i = 0; i < R; i++){
for(let j = 0; j < C; j++){
G[i] && G[i][j] === 1 ? filled++ : empty++
}
@kharioki
kharioki / toCamelCase.js
Created July 4, 2021 15:57
remove underscores or hyphens and uppercase the first letter
const str = "Yeah_so_many_underscores here";
// const str = "A-B-C";
// const newStr = str.replace(/_/g, " ");
const newStr = str.replace(/[_!@#$%^&*, -]/g, " ");
const arr = newStr.split(' ');
// remove first word
let arr1 = arr.slice(0,1)
let arr2 = arr.slice(1)
@kharioki
kharioki / tribonacci.js
Created July 4, 2021 15:55
Tribonacci - it works basically like a Fibonacci, but summing the last 3 (instead of 2) numbers of the sequence to generate the next.
function tribonacci(n) {
let seq = [1,1,1];
let index;
for (let i = 3; i < n; i++) {
seq.push(seq[seq.length - 1] + seq[seq.length - 2] + seq[seq.length - 3])
}
console.log(seq)
return seq.slice(0, n);
}
function digPow(n, p){
const digits = n.toString().split('').map(Number);
let sum = 0;
digits.forEach(digit => {
sum += Math.pow(digit , p);
p++;
})
return sum % n ? -1 : sum/n;
@kharioki
kharioki / countBits.js
Last active July 4, 2021 10:52
countBits
const countBits = n => n.toString(2).split('0').join('').length
countBits(1234);
@kharioki
kharioki / dropdown.js
Created June 30, 2021 03:16
A basic dropdown component implemented with react
/*
Prompt:
We have defined a basic dropdown via the Dropdown and DropdownItem components below, with example usage
in the ExampleNav component. The Dropdown and DropdownItem components have some problems, and also
have room for improvements (doesn't everything?) A couple items TODO here (make sure to explain with comments!)
0. How are you today? 😊
I am great. This is an interesting exercise
1. Please fix any obvious issues and make you see with the dropdown.
@kharioki
kharioki / maxSubArray.js
Created May 24, 2021 15:08
Finding the maximum subarray.
let arr1 = [13, -3, -25, 20, -3, -16, -23, 18, 20, -7, 12, -5, -22, 15, -4, 7];
function maxSubArray (nums) {
let maxC = nums[0];
let maxG = nums[0];
for (let i = 1; i < nums.length; i++) {
maxC = Math.max(nums[i], maxC + nums[i]);
maxG = maxC > maxG ? maxC : maxG;
}