Skip to content

Instantly share code, notes, and snippets.

View p0rsche's full-sized avatar
🧨
Working from home

Vladimir Gerasimov p0rsche

🧨
Working from home
View GitHub Profile
const assert = require('node:assert');
const parseInt = (n) => Number.parseInt(n)
function versionComparator(v1, v2) {
const v1arr = v1.split('.').map(parseInt);
const v1arrlen = v1arr.length;
const v2arr = v2.split('.').map(parseInt);
const v2arrlen = v2arr.length;
@p0rsche
p0rsche / Install V2Ray Client on OpenWRT and Configure Vmess
Last active October 30, 2023 16:15 — forked from amanjuman/Install V2Ray Client on OpenWRT and Configure Vmess
Install V2Ray Client on OpenWRT and Configure Vmess
### The original Author of this package had enabled CloudFlare JS verification. As a result, this automated script will not work.
### Therefore you have to download each package and install it manually.
## Change Directory
cd /tmp/
## Update opkg
opkg update
## If wget not installed already
@p0rsche
p0rsche / find_unique_number.js
Created January 30, 2023 10:02
Find unique number in the array of numbers where all except one have duplicates
/**
* Дан массив из чисел
* Все значения, кроме одного, повторяются.
* Найти уникальное значение за O(n).
* Известно, что уникальное значение одно и только одно
* Пример:
* Вход: [5,9,6,1,9,6,5]
* Выход: [1]
*
*/
@p0rsche
p0rsche / object_value_by_string_seq.js
Created January 24, 2023 09:10
Get object values by string sequence
// using string sequence, get object key
//'red.big.apple', {red: { big: { apple: 'apple'}}} => 'apple'
// 'red.fast.fancy.car', { red: { slow: 'something'}} => undefined
const get = (keySequence, nestedObject) => {
const seqArr = keySequence.split(".");
let result = nestedObject;
while (seqArr.length > 0) {
let key = seqArr.shift(); // seqArr now has length-1
@p0rsche
p0rsche / react_counter.js
Created January 24, 2023 07:17
React counter application
import React from "react";
import ReactDOM from "react-dom";
// counter app
function App() {
const [counter, setCounter] = React.useState(0);
const [working, setWorking] = React.useState(false);
React.useEffect(() => {
if (!working) return;
@p0rsche
p0rsche / promise_all.js
Created January 24, 2023 06:52
Promise.all realizations without Promise.all
// Simple Promise.all realization
function promiseAll(promises) {
try {
let len = promises.length;
let count = len;
const results = new Array(len).fill(null);
return new Promise((resolve, reject) => {
promises.forEach((p, idx) => {
p.then((res) => {
@p0rsche
p0rsche / find_missing_number_using_xor.js
Last active January 22, 2023 14:32
Find missing number in an array of n-1 numbers
/**
* Дан массив A из n — 1 целых чисел, находящихся в интервале от 1 до n.
* Все числа встречаются в нём ровно один раз, за исключением одного отсутствующего числа.
* Найти это отсутствующее число.
*/
const findMissingNumber = (A, n) => {
// XORing from 1 to n+1
@p0rsche
p0rsche / config.yml
Created March 8, 2021 14:35
circle build for node/yarn/eslint/webpack
version: 2.1
orbs:
aws-s3: circleci/aws-s3@2.0.0
node: circleci/node@4.2.0
workflows:
version: 2
build_and_deploy:
jobs:
@p0rsche
p0rsche / cards_avg.py
Last active August 19, 2020 07:12
Operations with dictionary - All hands on deck
faced_cards = {'Jack': 11, 'Queen': 12, 'King': 13, 'Ace': 14}
cards_in_hand = [int(x) if faced_cards.get(x) is None else faced_cards.get(x) for x in [input() for _ in range(6)]]
print(sum(cards_in_hand)/len(cards_in_hand))
# Sample Input 1:
#
# Ace
# 4
# 9
# Jack
@p0rsche
p0rsche / transcode.go
Created May 12, 2018 06:39 — forked from pranavraja/transcode.go
Stream/transcode video in real time with ffmpeg for chromecast
package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"log"