Skip to content

Instantly share code, notes, and snippets.

View veelenga's full-sized avatar
🇺🇦
Annihilating code

Vitalii Elenhaupt veelenga

🇺🇦
Annihilating code
View GitHub Profile
class FlashMessages extends React.Component {
constructor(props) {
super(props);
this.state = { messages: props.messages };
}
render () {
return(
<div>
# equal jsons
json1 = '{"polygons":[{"type":"rectangle","vertices":[{"x":1621.5,"y":1079.5},{"x":2674,"y":1079.5},{"x":2674,"y":2528},{"x":1621.5,"y":2528}],"category":"name"}]}'
json2 = '{"polygons":[{"type":"rectangle","category":"name","vertices":[{"x":1621.5,"y":1079.5},{"x":2674,"y":1079.5},{"x":2674,"y":2528},{"x":1621.5,"y":2528}]}]}'
rez1 = JSON.parse(json1)
rez2 = JSON.parse(json2)
rez1 == rez2 # true
@veelenga
veelenga / flatten.exs
Last active November 2, 2021 19:02
Flattening array in elixir
def flatten(list), do: flatten(list, []) |> Enum.reverse
def flatten([h | t], acc) when h == [], do: flatten(t, acc)
def flatten([h | t], acc) when is_list(h), do: flatten(t, flatten(h, acc))
def flatten([h | t], acc), do: flatten(t, [h | acc])
def flatten([], acc), do: acc
@veelenga
veelenga / clean_cache
Last active September 14, 2016 08:09
Clean dns cache on OS X
sudo killall -HUP mDNSResponder

Word

  • aw – a word (includes surrounding white space)
  • iw – inner word (does not include surrounding white space)

Sentences

  • as - a sentence
@veelenga
veelenga / chop.exs
Last active June 15, 2022 22:44
My solution for Chop guess exercise (Programming Elixir 1.3)
##############################
##Exercise: ModulesAndFunctions-6
defmodule Chop do
def guess(actual, lo..hi) when (lo <= hi) and (actual in lo..hi) do
current = guessing(lo, hi)
IO.puts "Is it #{current}"
guess(current, actual, lo..hi)
end
defp guess(value, actual, _) when value == actual, do: IO.puts value
@veelenga
veelenga / leftpad.cr
Last active March 24, 2016 21:10
left-pad for Crystal
class String
def leftpad(len : Int, char = ' ')
char, len = char.to_s, len - self.size
raise ArgumentError.new if char.size != 1
len > 0 ? (char * len + self) : self
end
end
@veelenga
veelenga / mongo.sh
Last active December 25, 2015 15:14
MongoDB export/import database
# create dump of the database on remote server
$ mongodump --host remote_host --db database_name
# import into database on localhost
$ mongorestore --host localhost --dir dump/database_name/ --db database_name --drop
@veelenga
veelenga / crystal_christmas_tree.txt
Last active March 9, 2024 18:02
Crystal Christmas Tree
$$$
crystal
crystal run
crystal build
crystal version
@veelenga
veelenga / import_export_mysql.md
Created December 10, 2015 10:48
Import/export mysql db

Create db dump:

mysqldump -u user -p db_name > db_name.sql

Restore db dump:

mysql -u user -p db_name < db_name.sql