Skip to content

Instantly share code, notes, and snippets.

View zafergurel's full-sized avatar
🏀
Focusing

Zafer Gürel zafergurel

🏀
Focusing
  • CTO@Perculus / PhDc@Ozyegin Uni.
  • İstanbul
  • X @xaferel
View GitHub Profile
@zafergurel
zafergurel / psql_useful_stat_queries.sql
Last active April 5, 2019 12:10 — 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 (postgres tables excluded)
@zafergurel
zafergurel / isVideoDark.js
Created February 15, 2019 10:04
Is Video Dark?
function isVideoDark(videoEl) {
var fuzzy = 0.1;
// create canvas
var canvas = document.createElement("canvas");
var videoWidth = videoEl.videoWidth;
var videoHeight = videoEl.videoHeight;
canvas.width = videoWidth;
canvas.height = videoHeight;
var ctx = canvas.getContext("2d");
@zafergurel
zafergurel / Howto convert a PFX to a seperate .key & .crt file
Created December 3, 2017 20:17 — forked from jesperronn/Howto convert a PFX to a seperate .key & .crt file
How to convert a .pfx SSL certificate to .crt/key (pem) formats. Useful for NGINX
source: http://www.markbrilman.nl/2011/08/howto-convert-a-pfx-to-a-seperate-key-crt-file/
`openssl pkcs12 -in [yourfile.pfx] -nocerts -out [keyfile-encrypted.key]`
What this command does is extract the private key from the .pfx file. Once entered you need to type in the importpassword of the .pfx file. This is the password that you used to protect your keypair when you created your .pfx file. If you cannot remember it anymore you can just throw your .pfx file away, cause you won’t be able to import it again, anywhere!. Once you entered the import password OpenSSL requests you to type in another password, twice!. This new password will protect your .key file.
Now let’s extract the certificate:
`openssl pkcs12 -in [yourfile.pfx] -clcerts -nokeys -out [certificate.crt]`
@zafergurel
zafergurel / sayi-bulmaca.jsx
Created June 18, 2017 19:07
ReactJs ile sayı bulmaca oyunu - https://jscomplete.com/repl için
const Textbox = (props) => {
return (
<input value={props.estimation} onKeyDown={props.keyDownHandler} onChange={props.changeHandler}/>
)
}
const Result = (props) => {
return (
<span style={{fontSize:14}}>#{props.order}. {props.estimation} {props.result}</span>
)
@zafergurel
zafergurel / String.convertToDate.js
Created December 15, 2016 07:16
String.convertToDate.js is a small extension method for the javascript String class. It's used to convert a string to a Date object by specifying a format string.
/*
The following code extends String class so that you can use convertToDate on a string object.
format can be a combination of "yy" or "yyyy" for year, "mm" for month and "dd" for day.
format is case-insensitive.
The seperator between date part markers may be "/", "." or "-".
Some examples:
"2016-12-31".convertToDate("yy-mm-dd") (same as "2016-12-31".convertToDate("yyyy-mm-dd"))
"31.12.2016".convertToDate("dd.MM.yyyy")
"12/31/2016".convertToDate("MM/dd/yyyy")
*/
@zafergurel
zafergurel / gist:5e969f3bdeff7db83648
Created December 4, 2015 16:39
Tablo ve Indekslerin Diskte Kapladıkları Yeri Sorgulama (MS SQL Server)
-- kaynak: http://stackoverflow.com/questions/15896564/get-table-and-index-storage-size-in-sql-server
SELECT
s.Name AS SchemaName,
t.NAME AS TableName,
p.rows AS RowCounts,
SUM(a.total_pages) * 8 AS TotalSpaceKB,
SUM(a.used_pages) * 8 AS UsedSpaceKB,
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
FROM
sys.tables t
@zafergurel
zafergurel / gist:a3f7edb8a44e3bef1cd6
Last active August 29, 2015 14:18
Bir Kelimenin Bir Karakter Dizgisi İçindeki Tekrarlanma Sıklığını Bulma (SQL)
/*
Bir Kelimenin Bir Karakter Dizgisi İçindeki Tekrarlanma Sıklığını Bulma
*/
DECLARE @wordToFind varchar(3) = 'Hello'
DECLARE @text varchar(300) = 'Hello World! Hello World! Hello World!'
SELECT (LEN(@text) - LEN(REPLACE(@text, @wordToFind, ''))) / LEN(@wordToFind) AS Tekrar
@zafergurel
zafergurel / database_cache_usage_sql
Created December 11, 2014 10:18
Hangi Veritabanı Önbellekte Ne Kadar Yer Tutuyor? (MS SQL Server)
/*
MS SQL Server'da hangi veritabanının ne kadar yer tuttuğunu gösteren aşağıdaki SQL'in çalışma süresi,
veritabanı büyüklüğüyle doğru orantılıdır. Birkaç dakika sürebilir.
*/
SELECT CAST(COUNT(1) * 8 / 1024.0 AS NUMERIC(10, 2)) AS CachedDataMB,
CASE database_id WHEN 32767 THEN '* Resource DB' ELSE DB_NAME(database_id) END AS DatabaseName, database_id DatabaseID
FROM sys.dm_os_buffer_descriptors
GROUP BY DB_NAME(database_id) , database_id ORDER BY DB_NAME(database_id)
@zafergurel
zafergurel / gist:94bb9d8663f6ab25370f
Created November 19, 2014 17:20
T-SQL ile Virgüllü Liste Ayrıştırma ve Oluşturma (SQL)
-- T-SQL ile Virgüllü Liste Ayrıştırma ve Oluşturma --
-- Örneklerde kullanmak üzere id alanında oluşan bir @idTable oluşturulur.
declare @idTable TABLE (id int)
insert @idTable (id) values (1)
insert @idTable (id) values (2)
/*
1. Virgüllü Listeye Çevirme
Users tablosundaki ilk 10 UserId değerini virgüllü liste haline getirme
@zafergurel
zafergurel / gist:caf7054381785b59060a
Created November 18, 2014 11:08
Adları, Ad Soyad olarak ayırmak (SQL)
-- Adları, Ad Soyad olarak ayırma
select left(FirstName, len(FirstName)-charindex(' ',reverse(FirstName))) as FirstName, right(FirstName, charindex(' ',reverse(FirstName))-1) as LastName from Users
-- Ad alanındaki ad/soyad verisiyle, ad ve soyad alanlarını güncelleme
update Users set FirstName = left(FirstName, len(FirstName)-charindex(' ',reverse(FirstName))), LastName = right(FirstName, charindex(' ',reverse(FirstName))-1)