Skip to content

Instantly share code, notes, and snippets.

MongoDB Cheat Sheet

Show All Databases

show dbs

Show Current Database

@nikbabchenko
nikbabchenko / resize-image.js
Created August 24, 2018 21:16 — forked from MikeRogers0/resize-image.js
An example of how to resize an image on the fly with javascript.
// The function that scales an images with canvas then runs a callback.
function scaleImage(url, width, height, liElm, callback){
var img = new Image(),
width = width,
height = height,
callback;
// When the images is loaded, resize it in canvas.
img.onload = function(){
var canvas = document.createElement("canvas"),
@nikbabchenko
nikbabchenko / squash-commits.sh
Created July 3, 2018 10:39 — forked from landsman/squash-commits.sh
git squash last two commits into one
git rebase --interactive HEAD~2
# we are going to squash c into b
pick b76d157 b
pick a931ac7 c
# squash c into b
pick b76d157 b
s a931ac7 c
@nikbabchenko
nikbabchenko / image-arraybuffer.js
Created June 28, 2018 19:34 — forked from candycode/image-arraybuffer.js
Create a jpg image from ArrayBuffer data
// Simulate a call to Dropbox or other service that can
// return an image as an ArrayBuffer.
var xhr = new XMLHttpRequest();
// Use JSFiddle logo as a sample image to avoid complicating
// this example with cross-domain issues.
xhr.open( "GET", "http://fiddle.jshell.net/img/logo.png", true );
// Ask for the result as an ArrayBuffer.
xhr.responseType = "arraybuffer";
@nikbabchenko
nikbabchenko / debounce.js
Created June 21, 2018 10:37 — forked from maxwihlborg/debounce.js
Simple javascript debounce function used when bundling up function calls.
/**
* Simple debounce function; usage:
*
* Create a function that only can be called once every 500 ms
*
* var df = debounce(function() {
* ... func body ...
* }, 500)
*
* Bind the function to an event
@nikbabchenko
nikbabchenko / singleton.js
Created May 9, 2018 12:05 — forked from sword-jin/singleton.js
JavaScript Singleton pattern -- es5
var dom = (function() {
var _counter = 0;
var instance;
function generateId () {
return "customId" + _counter ++;
}
function create (targetName, id) {
var el = document.createElement(targetName);
@nikbabchenko
nikbabchenko / open_app.html
Created April 19, 2018 13:45 — forked from noelrocha/open_app.html
Open app on Google Play or AppStore
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Open App</title>
<!--
URL Params:
customSchemeURL: Your custom scheme app
@nikbabchenko
nikbabchenko / README.md
Created February 28, 2018 15:26 — forked from pbojinov/README.md
Two way iframe communication- Check out working example here: http://pbojinov.github.io/iframe-communication/

Two way iframe communication

The main difference between the two pages is the method of sending messages. Recieving messages is the same in both.

Parent

Send messages to iframe using iframeEl.contentWindow.postMessage Recieve messages using window.addEventListener('message')

iframe

@nikbabchenko
nikbabchenko / iframe.html
Created February 23, 2018 09:44 — forked from cirocosta/iframe.html
Sending messages from child iframe to parent webpage
<!DOCTYPE html>
<html>
<head>
<title>My Iframe</title>
</head>
<body>
<button>Botão</button>
<script type="text/javascript">