Skip to content

Instantly share code, notes, and snippets.

@Biazus
Biazus / script.sql
Last active February 18, 2023 17:29
Find / Remove duplicates PostgreSQL
CREATE TABLE customer (
customer_id serial PRIMARY KEY,
first_name VARCHAR ( 50 ) NOT NULL,
last_name VARCHAR ( 50 ) NOT NULL,
address VARCHAR ( 50 ) NOT NULL
)
INSERT INTO customer (first_name, last_name, address) values ('John', 'B', 'x Avenue');
INSERT INTO customer (first_name, last_name, address) values ('John', 'B', 'x Avenue');
INSERT INTO customer (first_name, last_name, address) values ('Maria', 'Pena', 'Cal St.');
@Biazus
Biazus / postgresql-set-id-seq.sql
Created February 5, 2023 13:40
PostgreSQL set Next ID Sequence Value to MAX(id) from Table
-- Get Max ID from table
SELECT MAX(id) FROM table;
-- Get Next ID from table
SELECT nextval('table_id_seq');
-- Set Next ID Value to MAX ID
SELECT setval('table_id_seq', (SELECT MAX(id) FROM table));
@Biazus
Biazus / builder.py
Created March 21, 2020 23:55
Sample of builder design pattern
#!/usr/bin/env python3
from abc import ABC, abstractmethod
class AbstractEdgeBuilder(ABC):
@abstractmethod
def build_edge(self):
pass
@Biazus
Biazus / abstract_factory_azion.py
Last active March 12, 2020 18:32
Sample of abstract factory by Miller Biazus
#!/usr/bin/env python3
from abc import ABC, abstractmethod
class AbstractFunction(ABC):
@abstractmethod
def install_function(self):
pass
@Biazus
Biazus / context_manager.py
Last active February 14, 2023 17:18
Context Manager to override django settings
from django.conf import settings
class OverrideSetting(object):
"""
Enable the temporary change of a setting. Useful for disabling settings when testing or creating fixtures on dev
environment.
CAUTION: Do not use it to change production settings.
"""
@Biazus
Biazus / main.c
Created January 21, 2017 01:02
Deque-STL Solution (without deque) - https://www.hackerrank.com/challenges/deque-stl
#include <iostream>
#include <algorithm> // std::sort
#include <map>
using namespace std;
void printKMax(int arr[], int n, int k){
vector<pair<int,int> > d;
for(int i=0; i<n;i++){
d.push_back(make_pair(arr[i],i));
}
sort(d.rbegin(),d.rend());
@Biazus
Biazus / MonitorTester.java
Created March 26, 2015 13:12
Monitores em Java
import java.util.Random;
class MyMonitor {
private int data = 0;
private int turn = 1;
public synchronized void update(int id) throws InterruptedException {
while(turn != id)
@Biazus
Biazus / easy.cpp
Created November 21, 2014 13:10
11227 - The silver bullet
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <iostream>
#include <cstdlib>
using namespace std;
const int MAX = 120;
struct position {double x,y;};
@Biazus
Biazus / medium.cpp
Created November 21, 2014 13:09
10297 - Beavergnaw
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<cmath>
#include <iomanip>
#define PI 3.14159265
using namespace std;
@Biazus
Biazus / hash.c
Last active August 29, 2015 14:07
Etapa 5 Compiladores - hash
HASh_NODE *makeTemp(void)
{
static int nextTemp = 0;
static char tempName[256];
sprintf(tempName,"myStrangeeTemp%d", nextTemp++);
return hashInsert(HASH_VARIABLE, tempName);
}
HASh_NODE *makeLabel(void)