Skip to content

Instantly share code, notes, and snippets.

View cihangir's full-sized avatar
💭
Closed sourcing

Cihangir cihangir

💭
Closed sourcing
View GitHub Profile
@cihangir
cihangir / reflect.switch.go
Created May 30, 2013 07:52
switch / reflect Go
//get type of current value
typeOfKey := reflect.TypeOf(v).String()
//every v, will be a string at the end
switch typeOfKey {
//if we have an complex type, resolve it
case "map[string]interface {}":
//convert value to its real type
@cihangir
cihangir / regex.go
Created June 18, 2013 06:33
Go lang Regex
package main
import (
"fmt"
"regexp"
)
func main() {
//re := regexp.MustCompile("a(x*)b")
re := regexp.MustCompile("(buffal|tomat|potat)o$")
@cihangir
cihangir / co-tagged-places.cypher
Created July 1, 2013 16:51
Co-Tagged places — places related through tags Find places that are tagged with the same tags: Determine the tags for place x. What else is tagged the same as x that is not x.
START place=node:node_auto_index(name = "CoffeeShop1")
MATCH place-[:tagged]->tag<-[:tagged]-otherPlace
RETURN otherPlace.name, collect(tag.name)
ORDER BY length(collect(tag.name)) DESC, otherPlace.name
@cihangir
cihangir / who-like-x-also-like-y.cypher
Created July 1, 2013 16:53
Co-favorited places — users who like x also like y Find places that people also like who favorite this place: Determine who has favorited place x. What else have they favorited that is not place x.
START place=node:node_auto_index(name = "CoffeeShop1")
MATCH place<-[:favorite]-person-[:favorite]->stuff
RETURN stuff.name, count(*)
ORDER BY count(*) DESC, stuff.name
@cihangir
cihangir / iter.go
Created September 17, 2013 12:42
iter mgo
iter := collection.Find(nil).Sort("$natural").Tail(5 * time.Second)
for {
for iter.Next(&result) {
fmt.Println(result.Id)
lastId = result.Id
}
if err := iter.Close(); err != nil {
return err
}
if iter.Timeout() {
@cihangir
cihangir / indexusage.sql
Created July 30, 2014 04:12
Find missing indexes on tables
SELECT
relname,
seq_scan - idx_scan AS too_much_seq,
CASE
WHEN seq_scan - idx_scan > 0 THEN
'Missing Index?'
ELSE
'OK'
END,
pg_relation_size (relname :: regclass) AS rel_size,
@cihangir
cihangir / indexstatistics.sql
Created July 30, 2014 05:10
Index size/usage statistics
SELECT
T .tablename,
indexname,
C .reltuples AS num_rows,
pg_size_pretty (
pg_relation_size (quote_ident(T .tablename) :: TEXT)
) AS table_size,
pg_size_pretty (
pg_relation_size (
quote_ident(indexrelname) :: TEXT
@cihangir
cihangir / duplicateindexes.sql
Created July 30, 2014 05:16
Duplicate indexes
SELECT
pg_size_pretty (
SUM (pg_relation_size(idx)) :: BIGINT
) AS SIZE,
(ARRAY_AGG(idx)) [ 1 ] AS idx1,
(ARRAY_AGG(idx)) [ 2 ] AS idx2,
(ARRAY_AGG(idx)) [ 3 ] AS idx3,
(ARRAY_AGG(idx)) [ 4 ] AS idx4
FROM
(
@cihangir
cihangir / sublimesetttings.json
Created August 2, 2014 19:00
GoSublime.sublime-settings
{
"env":{"GOPATH": "/Users/siesta/go"},
"snippets": [
{
"match": {"global": true},
"snippets": [
{"text": "prl", "title": "fmt.Println(...)", "value": "fmt.Println(\"$1-->\", $1)"},
{"text": "prlpr", "title": "Pretty fmt.Println(...)", "value": "fmt.Printf(\"$1 %# v\", pretty.Formatter($1))"},
{"text": "prf", "title": "fmt.Printf(...)", "value": "fmt.Printf(\"$1 %+v\", $1)\n\n$2"},
{"text": "err", "title": "err clause", "value": "if err != nil {\n\treturn err$2\n}\n$3"},
@cihangir
cihangir / table_sizes.sql
Created June 19, 2015 22:19
Postgresql Table sizes
SELECT
nspname || '.' || relname AS "relation",
pg_size_pretty (pg_relation_size(C .oid)) AS "size"
FROM
pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C .relnamespace)
WHERE
nspname NOT IN (
'pg_catalog',
'information_schema'