Skip to content

Instantly share code, notes, and snippets.

Ufuk Uzun ufuk

Block or report user

Report or block ufuk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ufuk
ufuk / HttpServletRequestResponsePrinter.java
Created Sep 5, 2019
Utility to generate logging-purpose text for HttpServletRequest/Response
View HttpServletRequestResponsePrinter.java
package ...;
import ...JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.util.ContentCachingRequestWrapper;
import org.springframework.web.util.WebUtils;
@ufuk
ufuk / BaseMockito2Test.java
Last active Apr 11, 2019
Performs "verify no more interactions" check automatically for all mock objects (works with Mockito version 2). For detailed description: https://ufukuzun.wordpress.com/2019/04/09/ne-olup-bittiginden-habersiz-testlere-derman-mockscollector/ (Turkish)
View BaseMockito2Test.java
import org.apache.commons.lang3.ArrayUtils;
import org.junit.After;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
import org.mockito.junit.MockitoJUnitRunner;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.verifyNoMoreInteractions;
@RunWith(MockitoJUnitRunner.class)
@ufuk
ufuk / import-csv-file-from-s3-into-aws-redshift.sql
Created Jan 31, 2019
Import CSV file from S3 into AWS Redshift
View import-csv-file-from-s3-into-aws-redshift.sql
-- Before importing, you need to create table
CREATE TABLE example_table
(
...
);
-- Importing...
COPY example_table
FROM 's3://<BUCKET_NAME>/.../example_table.csv'
CREDENTIALS 'aws_access_key_id=...;aws_secret_access_key=...'
@ufuk
ufuk / bash-echo-time-by-timezone.sh
Created Jan 31, 2019
Echo time by timezone in BASH
View bash-echo-time-by-timezone.sh
echo "$(TZ='Europe/Moscow' date +%Y-%m-%d\ %H\:%M)"
# output => 2019-01-31 16:52
@ufuk
ufuk / postgresql-export-tables-to-s3-as-csv-file.sh
Last active Apr 8, 2019
BASH script to export some tables from the PostgreSQL database to S3 as CSV files.
View postgresql-export-tables-to-s3-as-csv-file.sh
#!/bin/bash
export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...
export AWS_DEFAULT_REGION=...
PG_HOST=...
PG_USER=...
PG_PASS='...'
PG_DB=...
@ufuk
ufuk / posgresql-lightspeed-alter-table.sql
Last active Nov 5, 2018
Increase performance of alter tables or any other expensive operations by increasing WORK_MEM parameter for current session in PostgreSQL
View posgresql-lightspeed-alter-table.sql
BEGIN;
LOCK TABLE ... IN SHARE MODE;
SET LOCAL WORK_MEM = '256MB';
ALTER TABLE ...;
COMMIT;
@ufuk
ufuk / TurkishNumberUtils.java
Last active Jun 5, 2018
Utils for converting numbers to Turkish words
View TurkishNumberUtils.java
public final class TurkishNumberUtils {
private static final String SPACE = " ";
private static final String EMPTY = "";
private static final String[] PERIOD_NAMES = {EMPTY, "bin", "milyon", "milyar", "trilyon", "katrilyon", "kentilyon"};
private static final String[] UNITS_TEXTS = {EMPTY, "bir", "iki", "üç", "dört", "beş", "altı", "yedi", "sekiz", "dokuz"};
@ufuk
ufuk / learn-which-process-has-allocated-the-tcp-port.sh
Last active Mar 23, 2018
Learn which process has allocated the TCP port (for example "8080")
View learn-which-process-has-allocated-the-tcp-port.sh
lsof -i tcp:8080
# Example output:
# COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
# java 86935 ...
@ufuk
ufuk / postgres-create-drop-index-without-locking.sql
Last active Mar 10, 2018 — forked from okanmenevseoglu/postgres-create-drop-index-online.sql
Create/Drop a database index without locking the table's selects, inserts, etc. on PostgreSQL
View postgres-create-drop-index-without-locking.sql
CREATE INDEX CONCURRENTLY your_index_name on your_table_name (your_column_name);
DROP INDEX CONCURRENTLY your_index_name;
@ufuk
ufuk / postgresql-cryptography-functions.sql
Last active Jan 29, 2018
Enable cryptography functions (pgcrypto extension) in PostgreSQL.
View postgresql-cryptography-functions.sql
CREATE EXTENSION pgcrypto;
-- Examples
SELECT ENCODE(DIGEST('password', 'md5'), 'hex');
SELECT ENCODE(DIGEST('password', 'sha1'), 'hex');
SELECT ENCODE(DIGEST('password', 'sha224'), 'hex');
SELECT ENCODE(DIGEST('password', 'sha256'), 'hex');
SELECT ENCODE(DIGEST('password', 'sha384'), 'hex');
SELECT ENCODE(DIGEST('password', 'sha512'), 'base64');
You can’t perform that action at this time.