Skip to content

Instantly share code, notes, and snippets.

View geo-stanciu's full-sized avatar

Geo Stanciu geo-stanciu

  • Bucharest, Romania
View GitHub Profile
@geo-stanciu
geo-stanciu / reset_sequences.sql
Last active November 16, 2019 19:44
Reset sequence values in PostgreSQL
do $$
declare
r record;
lMaxId bigint;
dbName text := 'devel';
begin
for r in with seq as (
select
table_name,
column_name,
@geo-stanciu
geo-stanciu / preparetcpmessage.cpp
Created October 30, 2019 15:04
Prepare JSON to be sent as a TCP Message
std::string json = "{\"msg\":\"There is a json in New Orleans...\"}";
unsigned long n = json.length();
unsigned long total = n + 5;
char *msg = (char *)malloc((total + 1) * sizeof(char));
if (!msg || total < 6)
{
if (msg)
free(msg);
@geo-stanciu
geo-stanciu / bitwiseop.c
Created October 30, 2019 14:36
Represent 4 byte int in byte array in c and c#
unsigned long n = 12121212;
unsigned long len = 0;
char msg[5];
msg[0] = (n >> 24) & 0xFF;
msg[1] = (n >> 16) & 0xFF;
msg[2] = (n >> 8) & 0xFF;
msg[3] = n & 0xFF;
msg[4] = 0;
@geo-stanciu
geo-stanciu / postgres_queries_and_commands.sql
Created August 4, 2019 10:38 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@geo-stanciu
geo-stanciu / shrink.sql
Last active May 11, 2019 17:00
SQL Server - Shrink the transaction log file
-- First, create a full backup
sqlcmd -d devel
use devel
go
select name,recovery_model_desc from sys.databases
go
ALTER DATABASE devel SET RECOVERY simple
go
@geo-stanciu
geo-stanciu / clear duplicate rows.sql
Created March 27, 2019 13:39
Clear Duplicate Rows
psql -d devel
-- delete duplicate rss - postgresql
DELETE FROM rss T1
USING rss T2
WHERE T1.ctid < T2.ctid
AND T1.rss_source_id = T2.rss_source_id
AND T1.title = T2.title
AND T1.link = T2.link;
@geo-stanciu
geo-stanciu / psql_useful_stat_queries.sql
Created March 20, 2019 10:18 — forked from anvk/psql_useful_stat_queries.sql
List of some useful Stat Queries for PSQL
--- PSQL queries which also duplicated from https://github.com/anvk/AwesomePSQLList/blob/master/README.md
--- some of them taken from https://www.slideshare.net/alexeylesovsky/deep-dive-into-postgresql-statistics-54594192
-- I'm not an expert in PSQL. Just a developer who is trying to accumulate useful stat queries which could potentially explain problems in your Postgres DB.
------------
-- Basics --
------------
-- Get indexes of tables
@geo-stanciu
geo-stanciu / git bare repository for dotfiles.txt
Created March 19, 2019 22:21
Using git bare repository for dotfiles
mkdir -p $HOME/.dotfiles
git init --bare $HOME/.dotfiles
alias config='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
(add this alias to .bashrc)
bash config config --local status.showUntrackedFiles no
Basic usage example:
@geo-stanciu
geo-stanciu / c - get current locat time.c
Created February 8, 2019 16:02
c - get current locat time
#include <time.h>
time_t rawtime;
struct tm * timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
setlocale(LC_ALL, "C");
strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", now);
@geo-stanciu
geo-stanciu / my.ini
Created November 30, 2018 20:42
my.ini
[mysqld]
datadir=D:/MariaDB 10.3/data
port=3306
innodb_buffer_pool_size=2045M
log-bin=binlog
max-binlog-size=500M
server-id=1
[client]
port=3306
plugin-dir=D:/MariaDB 10.3/lib/plugin