Skip to content

Instantly share code, notes, and snippets.

View EddiG's full-sized avatar
🛠️
making good stuff for good people

Eduard Gilmutdinov EddiG

🛠️
making good stuff for good people
View GitHub Profile
@EddiG
EddiG / rust.md
Last active August 4, 2023 06:21

Rust

Blanket implementation of a trait

Here the Speak trait has the blanket implementation for the references of any type that implement the Speak trait (Human type in the current example). That allows to pass Human, &Human, and &mut Human to the introduce method that expects a trait that has Speak trait implemented. The blanket implementation is necessary as Rust doesn't dereference types in traits.

trait Speak {
    fn speak(&self);
}

// Blanket implementation for &T
@EddiG
EddiG / ts-tricks.md
Last active October 24, 2022 12:56
TypeScript tips and tricks

TypeScript

Tools

  • zod - TypeScript-first schema validation with static type inference
  • tRPC - End-to-end typesafe APIs made easy
  • ts-toolbelt - Library of the TypeScript utilities

Generics

@EddiG
EddiG / react-hooks.md
Last active February 23, 2022 08:11
Contains React Hooks those I found useful

useDebounce

https://epicreact.dev/the-latest-ref-pattern-in-react/

function useDebounce(callback, delay) {
  // Using the useRef allows us to avoid any re-renders when the callback changes
  const callbackRef = React.useRef(callback)
  
  // The useLayoutEffect will be run before any other code, so that
  // we will have always latest callback function called in the debounce 
  // payload function.

Cheatsheets

Lowercase the filename

for file in *.png; do mv $file ${file:l}; done

Uppercase the filename

for file in *.png; do mv $file ${file:u}; done
@EddiG
EddiG / wireshark.md
Last active March 31, 2024 10:34
How to decrypt SSL/TLS traffic in Wireshark on MacOS

The main point is to save the SSL/TLS keys those used by the web browser (SSLKEYLOGFILE=/tmp/tmp-google/.ssl-key.log).
In the example below we run brand new instance of Google Chrome (--user-data-dir=/tmp/tmp-google do the trick):
SSLKEYLOGFILE=/tmp/tmp-google/.ssl-key.log /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --user-data-dir=/tmp/tmp-google
Then run the Wireshark and open the Preferences -> Protocols -> SSL, where we put the path to the SSL keys log file into the (Pre)-Master-Secret log filename field.
Now all SSL/TLS traffic from this browser instance will be decrypted.

@EddiG
EddiG / custom-local-domains.md
Last active March 4, 2019 12:16
This is instruction of how to have the arbitrary domain names locally for development purpose (MacOS)

How to setup local DNS server on MacOS

  1. brew install dnsmasq - install dnsmasq, a lightweight DNS server
  2. edit /usr/local/etc/dnsmasq.conf
  • uncomment no-resolv for prevent looking in /etc/resolv.conf
  • add server=8.8.8.8 and server=8.8.4.4 for addining Google's public DNS as a fallback
  • add address address=/my-custom-domain.com/127.0.0.1 so all requests to the my-custom-domain.com and its subdomains will be forwarded to the 127.0.0.1
  1. sudo brew services start dnsmasq - run dnsmasq as a service, so that it will work after restarting OS
  2. change the settings of your current connection to use the local DNS server
  • open Network Preferences
  • select your current internet connection, for example Wi-Fi

OddOccurrencesInArray

Algorithmic solution

function solution(A) {
    const oddValues = A.reduce((acc, a) => {
        if (acc.has(a)) {
            acc.delete(a)
        } else {
            acc.set(a, a)
        }
@EddiG
EddiG / bash.md
Last active September 6, 2019 15:42
All useful info regarding bash

Cheatsheets

Convert all flac files to the m4a

for m in *.flac; do ffmpeg -i "$m" -acodec alac "${m%.flac}.m4a"; done

In case when the .flac contains the picture additionally to the audio stream

for m in *.flac; do ffmpeg -i "$m" -c:a alac -c:v copy "${m%.flac}.m4a"; done
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// choose either `'stable'` for receiving highly polished,
// or `'canary'` for less polished but more frequent updates
updateChannel: 'stable',
@EddiG
EddiG / grep.md
Last active August 31, 2018 04:59
grep tips

Find all GraphQL queries/mutations in the directory

grep -Pzo 'gql`\s+(query|mutation)[\s\S]+?`' src/* -R | less

The output will be something like this

src/components/CurrentUser.js:gql`
  query CurrentUser {
    user {
 id