Skip to content

Instantly share code, notes, and snippets.

View ardeshireshghi's full-sized avatar

Ardeshir Eshghi ardeshireshghi

View GitHub Profile
@ardeshireshghi
ardeshireshghi / paste-img.js
Last active March 24, 2020 01:23
Pasting image from clipboard to web page
document.addEventListener('paste', e => {
const file = e.clipboardData.items[0].getAsFile();
if (!file.type.startsWith('image')) return;
const imgEl = new Image();
const reader = new FileReader();
imgEl.style.maxWidth = '100%';
reader.onload = e => {
import psycopg2
connection = psycopg2.connect("dbname=name-of-db user=prod password=xxxx host=somehost sslmode=verify-full sslrootcert=/usr/local/share/ca-certificates/ca-2019-root.pem")
@ardeshireshghi
ardeshireshghi / scroll-top-smooth-animate.js
Created November 15, 2018 12:13
Scroll with cool easing to top of the page
var scroller = (function () {
var startAnimation = function(duration) {
var startLocation = document.body.scrollTop || document.documentElement.scrollTop;
var startTime = Date.now();
var animationID;
var easeInOutCubic = function(time) {
return time < 0.5 ?
4 * time * time * time :
(time - 1) * (2 * time - 2) * (2 * time - 2) + 1;
class Observer {
constructor(observerCallbacks) {
this._observerCallbacks = observerCallbacks;
}
start(subscriptionFn) {
return subscriptionFn(this);
}
next(...args) {
<!DOCTYPE html>
<html>
<head>
<title>Enjoy fun animations on Web</title>
<style type="text/css" media="screen">
:root {
min-height: 100%;
font-size: 1em;
}
const validImageMimes = {
jpg: 'image/jpeg',
jpeg: 'image/jpeg',
png: 'image/png',
webp: 'image/webp'
};
const svgDocHeader = `<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">`;
#!/usr/bin/env bash
USER="$1"
SERVER_HOST="$2"
SOCKS_PORT="$3"
eval $(ssh-agent)
ssh-add "$HOME/.ssh/*.pem"
nohup ssh -CND "$SOCKS_PORT" "$USER"@"$SERVER_HOST" &
@ardeshireshghi
ardeshireshghi / swipe-carousel-bootstrap.js
Last active September 2, 2018 22:50
Adds sliding on touch devices to bootstrap carousel
@ardeshireshghi
ardeshireshghi / immutable-css.js
Created July 30, 2018 10:10
Change inline style of elements in a chained and immutable manner
/**
* Chaining immutable style changer
* Do not define any events on the element using addEventLister
* Use event delegation (do the parents)
* @param {String} name [description]
* @param {String} value [description]
* @return {Element}
*/
Element.prototype.css = function(name, value) {
const parentEl = this.parentNode;