Skip to content

Instantly share code, notes, and snippets.

View alpenzoo's full-sized avatar

Narcis Iulian Paun alpenzoo

View GitHub Profile
@alpenzoo
alpenzoo / README.md
Created May 27, 2019 15:22 — forked from valyala/README.md
Optimizing postgresql table for more than 100K inserts per second

Optimizing postgresql table for more than 100K inserts per second

  • Create UNLOGGED table. This reduces the amount of data written to persistent storage by up to 2x.
  • Set WITH (autovacuum_enabled=false) on the table. This saves CPU time and IO bandwidth on useless vacuuming of the table (since we never DELETE or UPDATE the table).
  • Insert rows with COPY FROM STDIN. This is the fastest possible approach to insert rows into table.
  • Minimize the number of indexes in the table, since they slow down inserts. Usually an index on time timestamp with time zone is enough.
  • Add synchronous_commit = off to postgresql.conf.
  • Use table inheritance for fast removal of old data:
@alpenzoo
alpenzoo / compose.es6.js
Created April 25, 2019 14:05 — forked from jaawerth/compose.es6.js
ES5 and ES6 implementations of compose - readable implementation, not optimized
function compose(...fnArgs) {
const [first, ...funcs] = fnArgs.reverse();
return function(...args) {
return funcs.reduce((res, fn) => fn(res), first(...args));
};
}
@alpenzoo
alpenzoo / jquery.deferred.promise.js
Created December 5, 2018 14:04 — forked from pbojinov/jquery.deferred.promise.js
simple jQuery Deferred example
function getData() {
var deferred = $.Deferred();
$.ajax({
'url': 'http://google.com',
'success': function(data) {
deferred.resolve('yay');
},
'error': function(error) {
deferred.reject('boo');
@alpenzoo
alpenzoo / index.html
Created September 21, 2018 12:08 — forked from romaricdrigon/index.html
Minimal HTML boilerplate
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Title</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
</head>
<body>
@alpenzoo
alpenzoo / traverse.js
Created September 14, 2018 08:10 — forked from tushar-borole/traverse.js
Object tree traversal in javascript (with lodash)
var data = {
"name": "root",
"contents": [
{
"name": "A",
"contents": [
{
"name": "fileA1",
"contents": []
}
@alpenzoo
alpenzoo / GoogleMapDivider.php
Created July 16, 2018 14:33 — forked from jamestomasino/GoogleMapDivider.php
PHP file to divide up a large image into Google Map tiles
<?php
//Larger images can require more memory and time
ini_set('memory_limit','2048M');
ini_set('max_execution_time','300');
//For testing purposes, I manually entered the input file name and destination folder
$destinationDir = 'tiles/';
$fileName = 'map.jpg';
if (!file_exists($destinationDir)) {
@alpenzoo
alpenzoo / jquery.hasattr.js
Created July 5, 2018 07:15 — forked from bjorn-ali-goransson/jquery.hasattr.js
jQuery hasAttr function
/* HAS ATTRIBUTE */
$.fn.hasAttr = function(attrName){
var element = this[0];
if(element.hasAttribute){
return element.hasAttribute(attrName);
@alpenzoo
alpenzoo / index.html
Created July 5, 2018 07:13 — forked from bjorn-ali-goransson/index.html
Minimal Bootstrap+jQuery+BootstrapJS+FontAwesome template
<!DOCTYPE html>
<html><head>
<meta charset="utf-8">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
</head><body>
<div class="container"><span class="btn btn-success"><i class="fa fa-coffee"></i></span></div>
</body></html>
@alpenzoo
alpenzoo / index.html
Created June 29, 2018 10:51 — forked from knownasilya/index.html
Google Maps Advanced Drawing
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="UTF-8">
<title>Drawing Tools</title>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false&libraries=drawing"></script>
<style type="text/css">
#map, html, body {
@alpenzoo
alpenzoo / scrollable.js
Created April 23, 2018 13:05 — forked from Alex1990/scrollable.js
Stop propagation for scroll/mousewheel
/**
* Stop propagation behavior for scroll of the element but body.
* Compatibility: IE9+
* Ref:
* - http://stackoverflow.com/questions/5802467/prevent-scrolling-of-parent-element#answer-16324762
* - https://developer.mozilla.org/en-US/docs/Web/Events/wheel
*/
;(function ($) {
$.fn.scrollable = function () {
this.on('wheel', function (event) {