Skip to content

Instantly share code, notes, and snippets.

View yevmoroz's full-sized avatar
🏠
Working from home

Yevhenii Moroz yevmoroz

🏠
Working from home
View GitHub Profile
@yevmoroz
yevmoroz / input_file_styling
Last active August 29, 2015 14:06
<input type="file" /> styling, better way, html valid
Better way to hide you **<input type="file" />** is to wrap it into <label> tag.
So it will look like so
<label class="file-chose">
<input type="file" />
</label>
After that you have to make css it styled to set input's display property to "none":
@yevmoroz
yevmoroz / relay_switch_esp8266.ino
Created January 28, 2018 16:48
Normal relay-based WiFi/MQTT switch
#include <PubSubClient.h>
#include <ESP8266WiFi.h>
void callback(char* topic, byte* payload, unsigned int length);
#define client_name "Switch"
#define wifi_ssid "Home"
#define wifi_password "secret"
#define mqtt_server "176.0.0.2"
@yevmoroz
yevmoroz / trie.js
Last active January 26, 2024 17:58
leetcode trie
/**
* Returns an instance of Trie data structure to fill with
* strings that can be searched through with high efficiency
* Example usage:
* ```
* const words = ['cats', 'dogs', 'racoons', 'foxes'];
* const t = trie();
* words.forEach(t.insert);
* t.search('cat'); // false
* t.search('cat', true); // true
@yevmoroz
yevmoroz / boundingbox.js
Created January 27, 2024 13:40
bounding rectangle box
const radToDeg = (v) => {
return (v * 180) / Math.PI;
};
const degToRad = (v) => {
return (v * Math.PI) / 180;
};
export const getBoundBox = (lat, lon, rangeInMeters = 10) => {
const latRad = degToRad(lat);
@yevmoroz
yevmoroz / fetch-utils.js
Last active January 27, 2024 14:38
basic fetch utils
/**
* Makes fetch call to API
* @param url
* @throws {ApiError}
*/
export const fetchApi = async (url: string) => {
const response = await fetch(url, {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
@yevmoroz
yevmoroz / randset.js
Created April 16, 2024 00:11
leetcode randset
class RandomizedSet {
constructor() {
this.set = new Map();
this.array = [];
}
insert(val) {
if (this.set.has(val)) {
return false;
}
@yevmoroz
yevmoroz / frequentwords.js
Last active April 16, 2024 13:31
leetcode frequent words
function topKFrequentWords(words, k) {
const freq = new Map();
for (const word of words) {
if (!freq.has(word)) {
freq.set(word, 1);
} else {
freq.set(word, freq.get(word) + 1);
}
}
@yevmoroz
yevmoroz / twosum.js
Created April 16, 2024 00:36
leetcode sum of 2 from list
/**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
function twoSum(nums, target) {
let mp = new Map()
for (let i = 0; i < nums.length; i++) {
let diff = target - nums[i]
@yevmoroz
yevmoroz / longestprefix.js
Created April 16, 2024 00:39
leetcode longest prefix
/**
* @param {string[]} strs
* @return {string}
*/
function longestCommonPrefix(strs) {
if (strs.length === 0) {
return "";
}
let prefix = strs[0];
@yevmoroz
yevmoroz / uncommonwords.js
Created April 16, 2024 13:17
leetcode uncommon words
function uncommonWords(s1, s2) {
const words1 = s1.split(' ');
const words2 = s2.split(' ');
const freq = new Map();
for (const word of words1) {
freq.set(word, (freq.get(word) || 0) + 1);
}