Skip to content

Instantly share code, notes, and snippets.

View Hubbitus's full-sized avatar

Pavel Alexeev aka Pahan-Hubbitus Hubbitus

View GitHub Profile
@mrw34
mrw34 / postgres.sh
Last active March 26, 2024 00:24
Enabling SSL for PostgreSQL in Docker
#!/bin/bash
set -euo pipefail
openssl req -new -text -passout pass:abcd -subj /CN=localhost -out server.req -keyout privkey.pem
openssl rsa -in privkey.pem -passin pass:abcd -out server.key
openssl req -x509 -in server.req -text -key server.key -out server.crt
chmod 600 server.key
test $(uname -s) = Linux && chown 70 server.key
docker run -d --name postgres -e POSTGRES_HOST_AUTH_METHOD=trust -v "$(pwd)/server.crt:/var/lib/postgresql/server.crt:ro" -v "$(pwd)/server.key:/var/lib/postgresql/server.key:ro" postgres:12-alpine -c ssl=on -c ssl_cert_file=/var/lib/postgresql/server.crt -c ssl_key_file=/var/lib/postgresql/server.key
@jesperorb
jesperorb / cors.md
Last active February 21, 2024 14:17
Handle CORS Client-side

Handle CORS Client-side

Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources (e.g. fonts) on a web page to be requested from another domain outside the domain from which the first resource was served. This is set on the server-side and there is nothing you can do from the client-side to change that setting, that is up to the server/API. There are some ways to get around it tho.

Sources : MDN - HTTP Access Control | Wiki - CORS

CORS is set server-side by supplying each request with additional headers which allow requests to be requested outside of the own domain, for example to your localhost. This is primarily set by the header:

Access-Control-Allow-Origin
@kimus
kimus / cx_oracle.md
Last active January 25, 2024 04:36
Installing python cx_oracle on Ubuntu

First of all, it just seems like doing anything with Oracle is obnoxiously painful for no good reason. It's the nature of the beast I suppose. cx_oracle is a python module that allows you to connect to an Oracle Database and issue queries, inserts, updates..usual jazz.

Linux

Step 1:

sudo apt-get install build-essential unzip python-dev libaio-dev

Step 2. Click here to download the appropriate zip files required for this. You'll need:

@hgmnz
hgmnz / query_planner.markdown
Created March 23, 2011 14:14
PostgreSQL query plan and SQL performance notes

Types of index scans

Indexes

Sequential Scan:

  • Read every row in the table
  • No reading of index. Reading from indexes is also expensive.
@usmansaleem
usmansaleem / sample_multiline.yml
Created September 4, 2017 23:03
multiline docker environment variable (via docker compose)
environment:
SERVER_NAME: "myserver.doma.in"
# Dummy key, cert
SSL_KEY: |-
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQD272jYrLm8Ph5QpMWFcWUO9Ua1EviykalP+tkMIg12yZ3GvezF
y8aayxdztB5vu68jqMeg6mOJlscWqFUhmAxj4mDknYenVzVX2CKzCgHlGninTKxY
61rXDaDZVpSZ+XIESJkaB0z9HHYtrSLr0coKmq4cT5TRptOnkpDlJxIRaQIDAQAB
AoGATcTYoGTFmiN2KK+8BWrRCQT2X9C5woNdb3LxKIEQ/HhC2HS4PRMQWW/c0vPH
IilZ30EoneUztAFochpRtWLNg4lJoLy04X/eNjEiC/imp0KSwWXmnuLhDcWcb0+M
@Hubbitus
Hubbitus / mount.afuse
Created February 11, 2017 15:00
Afuse sshfs automounter (/usr/sbin/mount.afuse)
#!/bin/bash
# afuse-sshfs mount helper to automatically mount remote machines.
# It is intended to be used as mount.afuse in command line. F.e. in /etc/fstab you may mount directory like:
# afuse# /mnt/remote afuse auto 0 0
# And then as regular user just do:
# $ cd /mnt/remote/user@remote.host/remote/path
# and folder /mnt/remote/user@remote.host will be mounted automatically!
#
# On Mac some also recommend add defer_permissions,noappledouble mount options.
@fikovnik
fikovnik / build.gradle
Created May 8, 2016 19:58
Building maven plugins by gradle
configurations {
mavenEmbedder
}
dependencies {
compile "org.apache.maven:maven-core:$mavenVersion"
compile "org.apache.maven:maven-plugin-api:$mavenVersion"
compile 'org.apache.maven.plugin-tools:maven-plugin-annotations:3.4'
mavenEmbedder "org.apache.maven:maven-embedder:$mavenVersion"
@sdpatil
sdpatil / Producer.java
Created December 26, 2016 03:46
Kafak Sample producer that sends Json messages
package com.mapr.kafka.serializer.json;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.connect.json.JsonSerializer;
import java.util.Properties;
@wolph
wolph / to_json.sql
Created April 6, 2012 10:35
Some functions to convert arrays/hstore to json :)
CREATE OR REPLACE FUNCTION escape_json (text) RETURNS text AS $$
SELECT replace($1, '''', '\'''); $$ LANGUAGE SQL IMMUTABLE;
CREATE OR REPLACE FUNCTION to_json(text) RETURNS text AS $$
SELECT escape_json($1) $$ LANGUAGE SQL IMMUTABLE;
CREATE OR REPLACE FUNCTION to_json(KEY text, value text) RETURNS text AS $$
SELECT '''' || to_json($1) || ''': ''' || to_json($2) || ''''; $$ LANGUAGE SQL IMMUTABLE;
@ohneda
ohneda / StandardDeviationCategory.groovy
Created July 21, 2011 23:07
StandardDeviation Category for groovy, inspired by Advanced Rails
import static java.lang.Math.*
import static java.math.RoundingMode.CEILING
class StandardDeviationCategory {
static Double mean(Collection list) {
list.with{
scale(sum() / size())
}
}