Skip to content

Instantly share code, notes, and snippets.

@sofakingworld
sofakingworld / gist:c47dd6a022934826f7c62769b814039b
Created August 22, 2016 18:15
TSQL (MS SQL) Query result as string
select Value+CHAR(32) from Table
for xml path('')
@sofakingworld
sofakingworld / Formulation of the problem
Last active August 22, 2016 19:47
TSQL (MS SQL) Polygon issues :)
Is a table containing identifiers and the vertex coordinates of figures.
P (Polygon_id int, point_id int, x float, y float)
Points are listed sequentially in a clockwise or counter- clockwise
1. It is necessary to write a function that returns the area of a selected polygon
2. It is necessary to write a function that returns the perimeter of the selected polygon
3. Check whether the point is on the specified coordinates inside the polygon
@sofakingworld
sofakingworld / Bracket balance function
Last active August 25, 2016 09:11
Bracket balance function
def brackets_balanced?(s)
brackets = [['(',')'],['[',']'],['{','}']]
flatten_brackets = brackets.flatten
close_brackets = brackets.map{|e| e[1]}
stack = ''
for i in 0..s.size do
stack += s[i] if flatten_brackets.include?(s[i])
stack = stack[0,stack.size-2] if brackets.include? [stack[stack.size-2,1],stack[stack.size-1,1]]
return false if close_brackets.include? stack[stack.size-1,1]
end
# test for Flatstack
# https://github.com/fs/test-tasks/tree/master/ruby
# Дана последовательность:
# 1
# 11
# 21
# 1211
# 111221
# 312211
# Нужно чтобы ваша программа могла продолжить данную последовательность. Можете в реализации использовать любые библиотеки.
@sofakingworld
sofakingworld / PSQL_tip_1
Created December 16, 2016 15:21
PSQL btree_gin index searching
/*
Making btree_gin index and using it in search
*/
CREATE EXTENSION btree_gin;
create index ix_table_1 on table_1 USING GIN (to_tsvector('simple', coalesce(table_1.seach_field.value::text, '')), table_1.id)
select * from table_1
where to_tsvector('simple', coalesce(table_1.seach_field.value::text, '')) @@ to_tsquery( 'example:*' );
-- index used
@sofakingworld
sofakingworld / Array.eachSlice
Last active October 16, 2017 13:45
JavaScript analog of EachSlice from Ruby
Array.prototype.eachSlice = function(size=1) {
return Array(Math.ceil(this.length / size))
.fill()
.map(( _, idx) => {
return this.slice(idx * size, (1 + idx) * size)
})
}
@sofakingworld
sofakingworld / config.exs
Last active February 14, 2018 09:17
Форматирование логов
.....
config :logger, :console,
level: :debug,
format: {LoggerFormatter, :format_log},
# For MacOS and "Postgres" App Users
# where var-10 is version of postgreSQL
cd /Users/$USER/Library/Application\ Support/Postgres/var-10/
rm postmaster.pid
@sofakingworld
sofakingworld / Example.ex
Last active March 25, 2018 15:18
Meta Elixir (Create methods dynamic)
defmodule Dynamic do
@methods ~w(method1 method2 method3)a
@methods
|> Enum.each( fn method ->
method_name = "prefix_#{method}"
def unquote(:"#{method_name}")(argument1, argument2) do
{unquote(method), argument1, argument2}
end
end)
@sofakingworld
sofakingworld / table.md
Last active November 6, 2018 11:51
beauty_kernel_list
Kernel's function with arity BeautyKernel's alias
!=/2 not_eq?
*/2 multiply
++/2 list_concat
+/1 plus
+/2 plus
--/2 list_remove
-/1 minus
-/2 minus