Skip to content

Instantly share code, notes, and snippets.

View edib's full-sized avatar

ibrahim edib kokdemir edib

View GitHub Profile
@jsanders
jsanders / go.md
Created March 30, 2012 03:47
Newton's method go vs. ruby comparison
package main

import("fmt"; "math")

func Sqrt(x float64) (z float64) {
  z, delta := 1.0, 1.0

  for delta > 1e-4 {
    z0 := z
@janlay
janlay / sort.go
Created March 15, 2012 09:40
Tour of Go #43: implement the square root function using Newton's method.
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
z := 1.0
for i := 1; i <= 100; i++ {
@ianunruh
ianunruh / quickstart-corosync.sh
Last active September 7, 2016 15:15
Corosync + Pacemaker basics on Ubuntu 14.04
#!/bin/bash
BIND_NETWORK="192.168.5.0"
SHARED_VIP="192.168.5.30"
apt-get update
apt-get install -y pacemaker ntp
# Configure Corosync
echo "START=yes" > /etc/default/corosync
sed -i "s/bindnetaddr: 127.0.0.1/bindnetaddr: $BIND_NETWORK/g" /etc/corosync/corosync.conf
@algotrader-dotcom
algotrader-dotcom / Apache : Permission denied because search permissions are missing on a component of the path
Created October 12, 2015 03:55
Apache : Permission denied because search permissions are missing on a component of the path
## This will be fixed by
find /var/www -type d -exec chmod 755 {} \;
find /var/www -type f -exec chmod 644 {} \;
@dideler
dideler / upgrade-postgres-9.3-to-9.4.md
Last active June 8, 2020 03:24
Upgrading PostgreSQL from 9.3 to 9.4 when upgrading Ubuntu 14.04 to 14.10

TL;DR

Create a backup:

pg_dumpall > mybackup.sql

Perform the upgrade:

sudo pg_dropcluster 9.4 main --stop
@eulerto
eulerto / postgres-non-default-settings
Last active September 10, 2020 10:06
PostgreSQL non-default settings + version
SELECT name, current_setting(name), source, sourcefile, sourceline FROM pg_settings WHERE (source <> 'default' OR name = 'server_version') AND name NOT IN ('config_file', 'data_directory', 'hba_file', 'ident_file');
-- Order by one indexed column (FAST)
newsdesk_production=# explain analyze select * from pressreleases order by published_at DESC limit 100;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.00..249.91 rows=100 width=1207) (actual time=26.070..716.453 rows=100 loops=1)
-> Index Scan Backward using pressreleases_published_at_index on pressreleases (cost=0.00..964766.62 rows=386042 width=1207) (actual time=26.067..716.343 rows=100 loops=1)
Total runtime: 716.709 ms
(3 rows)
- Order by two separately indexed columns (SLOW)
@ibussieres
ibussieres / upgrade_pg.sh
Last active May 26, 2021 04:29
Upgrade PostgreSQL 9.1 to 9.3 on Ubuntu 12.04
echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-9.3 postgresql-server-dev-9.3 postgresql-contrib-9.3 -y
sudo su - postgres -c "psql template1 -p 5433 -c 'CREATE EXTENSION IF NOT EXISTS hstore;'"
sudo su - postgres -c "psql template1 -p 5433 -c 'CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";'"
sudo su - postgres -c "service postgresql stop"
sudo su - postgres -c '/usr/lib/postgresql/9.3/bin/pg_upgrade -b /usr/lib/postgresql/9.1/bin -B /usr/lib/postgresql/9.3/bin -d /var/lib/postgresql/9.1/main/ -D /var/lib/postgresql/9.3/main/ -O "-c config_file=/etc/postgresql/9.3/main/postgresql.conf" -o "-c config_file=/etc/postgresql/9.1/main/postgresql.conf"'
@edib
edib / pg-upgrade.sh
Last active February 4, 2022 20:54
Upgrade postgres 9.5 to 11 with pg_upgrade
# See https://wiki.postgresql.org/wiki/Using_pg_upgrade_on_Ubuntu/Debian for more information and warning!
# Check first
/usr/lib/postgresql/11/bin/pg_upgrade \
-b /usr/lib/postgresql/9.6/bin \
-B /usr/lib/postgresql/11/bin \
-d /var/lib/postgresql/9.6/main \
-D /var/lib/postgresql/11/main \
-o ' -c config_file=/etc/postgresql/9.6/main/postgresql.conf' \
-O ' -c config_file=/etc/postgresql/11/main/postgresql.conf' \
@angeloped
angeloped / change_vol.py
Created March 31, 2019 16:35
Change master audio volume in Linux using python.
import subprocess
def get_master_volume():
proc = subprocess.Popen('/usr/bin/amixer sget Master', shell=True, stdout=subprocess.PIPE)
amixer_stdout = proc.communicate()[0].split('\n')[4]
proc.wait()
find_start = amixer_stdout.find('[') + 1
find_end = amixer_stdout.find('%]', find_start)
return float(amixer_stdout[find_start:find_end])