Skip to content

Instantly share code, notes, and snippets.

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

Mohammad Khanafi thekingofbandit

🏠
Working from home
View GitHub Profile
@thekingofbandit
thekingofbandit / postgres-cheatsheet.md
Created June 27, 2020 17:26 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@thekingofbandit
thekingofbandit / imagemagick.md
Created June 27, 2020 17:27 — forked from Kartones/image-and-video.md
Imagemagick & ffmpeg commands

imagemagick

  • Nornalize all images of a folder converting them to jpgs with 90% quality (warning, removes original files):
rename 's/\.JPG$/\.jpg/' *.JPG
rename 's/\.JPEG$/\.jpg/' *.JPEG
rename 's/\.jpeg$/\.jpg/' *.jpeg
mogrify -format jpg *.png
mogrify -resize 1600x1280\> -quality 90 *.jpg
rm *.png
@thekingofbandit
thekingofbandit / no-css
Created June 27, 2020 17:28 — forked from Kartones/no-css
Bookmark to remove all CSS, JS and iframesfrom a page. Just paste as new bookmark
javascript:%20var%20el,%20i,%20size;%20%20for(i=0,%20size=document.styleSheets.length;%20i<size;%20i++)%20{%20void(document.styleSheets.item(i).disabled=true);%20}%20%20el%20=%20document.getElementsByTagName('script');%20%20while%20(el.length%20>%200)%20{%20%20void(el[0].parentNode.removeChild(el[0]));%20%20}%20%20el%20=%20document.getElementsByTagName('link');%20%20while%20(el.length%20>%200)%20{%20%20void(el[0].parentNode.removeChild(el[0]));%20%20}%20%20el%20=%20document.getElementsByTagName('iframe');%20%20while%20(el.length%20>%200)%20{%20%20void(el[0].parentNode.removeChild(el[0]));%20%20}%20%20el%20=%20document.getElementsByTagName('*');%20%20for%20(%20i=0,%20size=el.length;%20i%20<%20size;%20i++)%20{%20%20void(el[i].style.cssText%20=%20'');%20%20}
@thekingofbandit
thekingofbandit / request.js
Created July 4, 2020 18:45 — forked from sheharyarn/request.js
Axios Request Wrapper for React (https://to.shyr.io/axios-requests)
/**
* Axios Request Wrapper
* ---------------------
*
* @author Sheharyar Naseer (@sheharyarn)
* @license MIT
*
*/
import axios from 'axios'
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="[push to chart data]">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script src="https://cdn.jsdelivr.net/lodash/4/lodash.min.js"></script>
@thekingofbandit
thekingofbandit / array_iteration_thoughts.md
Created September 16, 2020 06:25 — forked from ljharb/array_iteration_thoughts.md
Array iteration methods summarized

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it much simpler to think about both the old list and the new one, what they contain, and

@thekingofbandit
thekingofbandit / Documentation.md
Created September 23, 2020 16:21 — forked from KartikTalwar/Documentation.md
Rsync over SSH - (40MB/s over 1GB NICs)

The fastest remote directory rsync over ssh archival I can muster (40MB/s over 1gb NICs)

This creates an archive that does the following:

rsync (Everyone seems to like -z, but it is much slower for me)

  • a: archive mode - rescursive, preserves owner, preserves permissions, preserves modification times, preserves group, copies symlinks as symlinks, preserves device files.
  • H: preserves hard-links
  • A: preserves ACLs
@thekingofbandit
thekingofbandit / ReactClassComponentWithMethods.jsx
Last active February 7, 2021 11:12
React Class Component Methods
import React, { Component } from 'react';
import PropTypes from 'prop-types';
class reactClassComponentWIthMethods extends Component {
constructor(props) {
super(props);
}
componentWillMount() {
/*****************
* cellBlockA.js *
*****************
*
* Good morning, Dr. Eval.
*
* It wasn't easy, but I've managed to get your computer down
* to you. This system might be unfamiliar, but the underlying
* code is still JavaScript. Just like we predicted.
*

SSH keys

Create

ssh-keygen -o

You can view the created files (one without extension and one with .pub) under ~/.ssh/. When creating several of them, you may want to rename them appropriately (e.g. work, pers...).

Add them

to the relevant github account: https://github.com/settings/ssh/new

Configuration

The configuration file for ssh is usually not created by default so we create it: