Skip to content

Instantly share code, notes, and snippets.

@amit08255
amit08255 / typescript.md
Last active February 19, 2023 17:54
TypeScript Cheatsheet

TypeScript Cheatsheet

Extracting and reusing return type of a function

declare function f1(): { a: number; b: string };
 
type T0 = ReturnType<() => string>;
type T1 = ReturnType<(s: string) => void>;
type T2 = ReturnType&lt;() =&gt; T&gt;;
@amit08255
amit08255 / html5-form-validations.md
Created January 13, 2023 11:06
HTML5 Form Validation Tricks

HTML5 Form Validation Tricks

Disable submit button if any input HTML5 validations failed

form.validated-forms:invalid {
  button[type="submit"]:not(:disabled) {
    opacity: 0.5;
    pointer-events: none;
 }
@amit08255
amit08255 / react-hydration.md
Created January 5, 2023 08:27
Fix React Hydration Errors

Fix React Hydration Errors

Remove content from initial render (WORKS BEST)

export default function NoFirstRender({ theDate }) {
	const [hydrated, setHydrated] = React.useState(false);
	React.useEffect(() => {
		// This forces a rerender, so the date is rendered
 // the second time but not the first
@amit08255
amit08255 / sql.md
Last active February 3, 2023 12:13
SQL cheatsheet

SQL Cheatsheet

Get all columns in rows by distinct value in one column

select distinct on (category) * from "TargetGoal";

Select a column as boolean

function interceptNetworkRequests(ee) {
const open = XMLHttpRequest.prototype.open;
const send = XMLHttpRequest.prototype.send;
const isRegularXHR = open.toString().indexOf('native code') !== -1;
// don't hijack if already hijacked - this will mess up with frameworks like Angular with zones
// we work if we load first there which we can.
if (isRegularXHR) {
@amit08255
amit08255 / pdf2png.js
Created December 7, 2022 17:08 — forked from grantmichaels/pdf2png.js
PDF to PNG with Node.js and GhostScript
var exec = require('child_process').exec;
var fs = require('fs');
var util = require('util');
var http = require('http');
var url = require('url');
var PDFDocument = require('pdfkit'); // http://pdfkit.org/
http.createServer(function (req, res) {
@amit08255
amit08255 / rxjs.md
Last active November 24, 2022 17:49
RXJS Cheatsheet

RXJS CheatSheet

Basic Concept

The essential concepts in RxJS which solve async event management are:

  • Observable: represents the idea of an invokable collection of future values or events.
  • Observer: is a collection of callbacks that knows how to listen to values delivered by the Observable.
  • Subscription: represents the execution of an Observable, is primarily useful for cancelling the execution.
  • Operators: are pure functions that enable a functional programming style of dealing with collections with operations like map, filter, concat, reduce, etc.
@amit08255
amit08255 / guide.md
Created November 20, 2022 14:26 — forked from neoneye/guide.md
Install GraphicsMagick on AWS EC2 running Ubuntu Linux
@amit08255
amit08255 / json-generator.md
Created November 18, 2022 12:21
JSON Generator Examples

These cheatsheet works for JSON-Generator

Using Custom Function For Final Data Result

[
  {
    data: [
      '{{repeat(15, 45)}}',
 {
@amit08255
amit08255 / docker-cheatsheet.md
Created October 18, 2022 17:08
Docker CheatSheet

Docker CheatSheet

Connect to postgreSQL using terminal

Docker compose example with postgreSQL:

version: "3"
services:
 # Postgres