Skip to content

Instantly share code, notes, and snippets.

View victory-sokolov's full-sized avatar
🎯
Focusing

Viktor Sokolov victory-sokolov

🎯
Focusing
View GitHub Profile
const uuid = () => Date.now().toString(36) + Math.random().toString(36).substr(2);
@victory-sokolov
victory-sokolov / git-reference.md
Last active March 25, 2023 17:50
Git commands reference

Git command reference

// remove all files marked as deleted from git git ls-files --deleted -z | xargs -0 git rm

// change remote url from HTTP to SSH git remote set-url origin git@github.com:USERNAME/REPOSITORY.git

// add files to the previous commit without modifying commit message git commit --amend --no-edit

@victory-sokolov
victory-sokolov / object-snippet.js
Last active November 29, 2021 20:38
Different object snippets
const obj = {
name: "Fenix",
age: 1000,
sallary: "9000$"
}
// Omit specific keys from object
const omit = (obj, ...props) => {
const filteredArray = Object.entries(obj).filter(([key, value]) => !props.includes(key));
return Object.fromEntries(filteredArray);
@victory-sokolov
victory-sokolov / https-python-server.py
Created August 26, 2021 09:18
Python https server
import http.server
import ssl
import os
def start_server(host: str = '127.0.0.1', port: int = 4443):
httpd = http.server.HTTPServer((host, port), http.server.SimpleHTTPRequestHandler)
server = http.server.HTTPServer.get_request(httpd)[0].getsockname()
print(f'Server is running at https://{server[0]}:{server[1]}')
@victory-sokolov
victory-sokolov / isMobile.ts
Created May 4, 2021 15:10
Check if user is on a mobile device
const isMobileDevice = (): boolean => {
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i
.test(navigator.userAgent)) {
return true;
}
return false;
};
@victory-sokolov
victory-sokolov / unionWithExclusion.ts
Last active September 9, 2021 09:50
Union two objects and exclude false values
/**
* Union two objects and exclude false values when merging same keys
* @param left
* @param right
* @returns New combined object
*/
export function unionWithExclusion(left: object, right: object): object {
return [left, right].reduce((prev: any, current) => {
if(current) {
Object.entries(current).map(([key, value]) => {
@victory-sokolov
victory-sokolov / dumptDataToFile.js
Created February 16, 2021 09:39
Download object data to a file
dataToFile(content, fileName, contentType) {
const a = document.createElement("a");
const file = new Blob([content], {type: contentType});
a.href = URL.createObjectURL(file);
a.download = fileName;
a.click();
}
dataToFile(JSON.stringify(data), 'results.json', 'application/json');
@victory-sokolov
victory-sokolov / cameraJS
Last active December 8, 2020 10:16
Get camera feed
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1, maximum-scale=1">
<title>Document</title>
</head>
<body>
<div class="display-cover">
@victory-sokolov
victory-sokolov / CameraAccess.js
Created November 5, 2020 09:14
React Native WebView frontal camera access
import React from 'react';
import {
StyleSheet,
StatusBar,
PermissionsAndroid,
} from 'react-native';
import {
Header,
Colors,
@victory-sokolov
victory-sokolov / object-to-dict.py
Last active November 23, 2023 14:38
Convert SQLAlchemy object to Python dictionary
users = User.query.filter_by(id=id).first()
users = []
for user in users:
dictret = dict(receipt.__dict__)
dictret.pop('_sa_instance_state', None)
users.append(dictret)