Skip to content

Instantly share code, notes, and snippets.

View igtulm's full-sized avatar
:octocat:

Igor Tulmentyev igtulm

:octocat:
View GitHub Profile
@peterhellberg
peterhellberg / max_parallelism.go
Created June 24, 2013 07:25
Find out the max value for GOMAXPROCS on your machine.
package main
import (
"fmt"
"runtime"
)
func MaxParallelism() int {
maxProcs := runtime.GOMAXPROCS(0)
numCPU := runtime.NumCPU()
@scaryguy
scaryguy / change_primary_key.md
Last active February 4, 2025 02:09
How to change PRIMARY KEY of an existing PostgreSQL table?
-- Firstly, remove PRIMARY KEY attribute of former PRIMARY KEY
ALTER TABLE <table_name> DROP CONSTRAINT <table_name>_pkey;
-- Then change column name of  your PRIMARY KEY and PRIMARY KEY candidates properly.
ALTER TABLE <table_name> RENAME COLUMN <primary_key_candidate> TO id;
@eberle1080
eberle1080 / PyUnicode_AsASCIIString.cpp
Created October 22, 2013 15:54
An example of how to use PyUnicode_AsASCIIString
// Assumption: you have a variable named "pyobj" which is
// a pointer to an instance of PyUnicodeObject.
PyObject* temp = PyUnicode_AsASCIIString(pyobj);
if (NULL == temp) {
// Means the string can't be converted to ASCII, the codec failed
printf("Oh noes\n");
return;
}
@cpq
cpq / Stack.md
Last active March 29, 2025 06:49
Why stack grows down

Why stack grows down

Any running process has several memory regions: code, read-only data, read-write data, et cetera. Some regions, such as code and read-only data, are static and do not change over time. Other regions are dynamic: they can expand and shrink. Usually there are two such regions: dynamic read-write data region, called heap, and a region called stack. Heap holds dynamic memory allocations, and stack is mostly used for keeping function frames.

Both stack and heap can grow. An OS doesn't know in advance whether stack or heap will be used predominantly. Therefore, an OS must layout these two memory regions in a way to guarantee maximum space for both. And here is the solution:

  1. Layout static memory regions at the edges of process's virtual memory
  2. Put heap and stack on edges too, and let them grow towards each other: one grows up, one grows down
@jarvisschultz
jarvisschultz / CMakeLists.txt
Last active August 11, 2019 17:21
Embedding Python in C++ Test
cmake_minimum_required(VERSION 2.8.3)
project(pycpp_test)
find_package(catkin REQUIRED COMPONENTS
roscpp
)
find_package(PythonLibs 3.4 EXACT)
catkin_package()
@tasdikrahman
tasdikrahman / python_tests_dir_structure.md
Last active February 10, 2025 22:15
Typical Directory structure for python tests

A Typical directory structure for running tests using unittest

Ref : stackoverflow

The best solution in my opinion is to use the unittest [command line interface][1] which will add the directory to the sys.path so you don't have to (done in the TestLoader class).

For example for a directory structure like this:

new_project

├── antigravity.py

@tkrajina
tkrajina / call_method_with_reflection.go
Created April 1, 2016 09:14
Golang, call method (and fill arguments) with reflection
package main
import (
"fmt"
"reflect"
)
type Aaa struct {
a string
}
@valyala
valyala / README.md
Last active March 20, 2025 08:44
Optimizing postgresql table for more than 100K inserts per second

Optimizing postgresql table for more than 100K inserts per second

  • Create UNLOGGED table. This reduces the amount of data written to persistent storage by up to 2x.
  • Set WITH (autovacuum_enabled=false) on the table. This saves CPU time and IO bandwidth on useless vacuuming of the table (since we never DELETE or UPDATE the table).
  • Insert rows with COPY FROM STDIN. This is the fastest possible approach to insert rows into table.
  • Minimize the number of indexes in the table, since they slow down inserts. Usually an index on time timestamp with time zone is enough.
  • Add synchronous_commit = off to postgresql.conf.
  • Use table inheritance for fast removal of old data:
@ik5
ik5 / time_format.go
Created November 9, 2016 09:04
A full example of all possible time formats in Golang
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println("Times: ")
t := time.Now()
@bowmanmike
bowmanmike / dynamic_function_calls.go
Created February 22, 2017 19:06
Golang Dynamic Function Calling
package main
import (
"fmt"
)
// Use map[string]interface{} to pair functions to name
// Could maybe use anonymous functions instead. Might be clean
// in certain cases
var funcMap = map[string]interface{}{