Skip to content

Instantly share code, notes, and snippets.

View alpenzoo's full-sized avatar

Narcis Iulian Paun alpenzoo

View GitHub Profile
@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 / 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));
};
}
<?php
// PHP Simple Proxy
// Responds to GET or POST
//I would use session or other checks to prevent abuse.
//do not put it in the wild without limiting usage to a domain, list of urls etc
$url = ($_POST['url']) ? $_POST['url'] : $_GET['url'];
$url = urldecode($url);
if(empty($url)){
@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:
<?php
/** Encryption setup CODE **/
$key = openssl_pkey_new(array('private_key_bits' => 2048));
$private_key = openssl_pkey_get_details($key);
$public_key = $private_key['key'];
echo "<pre>";
print_r($private_key);
echo "</pre>";
@alpenzoo
alpenzoo / gist:2d83444fcd1f17b522f0aea92b3d67c0
Created August 20, 2019 14:54
sample encapsulated variables, setters and getters
function myfunc(){
var data = {
name:'',
age:0,
roles:[],
prefs:{
timezone:1,
theme:'light',
lng:'en'
}
(function(x, f=()=>x){
var x;
var y=x;
x=2;
return [x,y,f()];
})(1)
@alpenzoo
alpenzoo / sample-php-headers.php
Created December 11, 2019 09:13 — forked from ScottPhillips/sample-php-headers.php
PHP Header Examples
301 moved permanently (redirect):
<?php
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.example.com');
die();
?>
302 moved temporarily(redirect):
<?php
header('Location: http://www.example.com');
<?php
$opt = array(
"--zoom"=>'1',
"--disable-smart-shrinking"=>'',
"--page-size"=>'A4',
"--orientation"=>'Landscape',
"--margin-bottom"=>'0',
"--margin-top"=>'0',
"--margin-left"=>'0',
"--margin-right"=>'0'
@alpenzoo
alpenzoo / chrome_no-cors_no-ca.bat
Created February 14, 2020 12:57
.bat file to open chrome browser with disabled security, handy for web development in unfriendly environment. not for browsing the web.
start .\chrome.exe --disable-web-security --ignore-certificate-errors --user-data-dir="D:/Chrome"
exit