Skip to content

Instantly share code, notes, and snippets.

View maxsimych's full-sized avatar

Max maxsimych

View GitHub Profile
@maxsimych
maxsimych / gist:2167cd1f90f7dfc1ce939a11cc6cf1b7
Created September 17, 2024 10:39
Convert unsigned to signed
const convertToSigned = num => num << 24 >> 24
@maxsimych
maxsimych / gist:8bf96b96fd242576fc8001bf65618c40
Last active September 17, 2024 10:40
Convert number to 32-bit binary string.
const toBinStr = num => (num >>> 0).toString(2).padStart(32,'0').match(/.{1,8}/g).join(' ')
@maxsimych
maxsimych / promiseChain.js
Created January 5, 2023 15:36
Example of JavaScript promise chain
function createPromiseChain(arrayForAsyncTasks) {
let promiseChain = Promise.resolve();
for (let i = 0; i < arrayForAsyncTasks.length; i++) {
const dataForAsyncTask = arrayForAsyncTasks[i];
promiseChain = promiseChain.then(() => {
return doAsyncTask(dataForAsyncTask);
});
}
2021-06-23 10:24:58,455 [ 1660] ERROR - llij.ide.plugins.PluginManager - null
java.lang.ExceptionInInitializerError
at com.intellij.ide.IdeEventQueue.<clinit>(IdeEventQueue.java:80)
at com.intellij.idea.StartupUtil.replaceSystemEventQueue(StartupUtil.java:788)
at com.intellij.idea.StartupUtil.patchSystem(StartupUtil.java:772)
at com.intellij.idea.ApplicationLoader.executeInitAppInEdt(ApplicationLoader.kt:58)
at com.intellij.idea.ApplicationLoader.access$executeInitAppInEdt(ApplicationLoader.kt:1)
at com.intellij.idea.ApplicationLoader$initApplication$1$1.run(ApplicationLoader.kt:363)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:316)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
@maxsimych
maxsimych / customNode.js
Last active April 17, 2020 12:11
Custom functional node example
import * as React from "react";
import {DefaultNode} from "react-dag";
import { css, StyleAttribute } from "glamor";
import { getSettings } from "../../settings/dag-settings";
import { theme } from "../../styles";
export const endPointStyles = css({
"&.right": {
left: "190px",
@maxsimych
maxsimych / fileURL.js
Last active November 26, 2019 08:03
How to store file in redux
//instead of storing the File in the store I create an URL for the file and store that in the store
onDrop = (filesAccepted) => {
const file = filesAccepted[0];
const url = URL.createObjectURL(file);
this.props.fileSelected({name: file.name, url: url}); /* this dispatches an action */
};
//then when I need the actual content I simply retrieve it like this:
const blob = await fetch(file.url).then(r => r.blob());
@maxsimych
maxsimych / postgres-cheatsheet.md
Last active November 10, 2019 06:10 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Connecting:

psql -U postgres

or

psql user_name(postgres) -h 127.0.0.1 -d db_name
@maxsimych
maxsimych / checkErr.go
Created October 26, 2019 20:39
golang checkErr
func checkErr(err error) {
if err != nil {
panic(err)
}
}
@maxsimych
maxsimych / golangPackageList.md
Created October 10, 2019 06:56
useful Golang packages collection #Golang
  • Go-spew implements a deep pretty printer for Go data structures - "github.com/davecgh/go-spew/spew"
  • dotenv for Go - "github.com/joho/godotenv"
@maxsimych
maxsimych / condition&&expression
Last active July 28, 2019 18:54
condition&&expression construction JS
true && expression always evaluates to expression, and false && expression always evaluates to false.
(Therefore, if the condition is true, the element right after && will appear in the output. If it is false, React will ignore and skip it)
JSX example:
<div>
<h1>Hello!</h1>
{unreadMessages.length > 0 &&
<h2>
You have {unreadMessages.length} unread messages.
</h2>
}