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
@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

Word

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

Sentences

  • as - a sentence
@veelenga
veelenga / clean_cache
Last active September 14, 2016 08:09
Clean dns cache on OS X
sudo killall -HUP mDNSResponder
@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
# 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
class FlashMessages extends React.Component {
constructor(props) {
super(props);
this.state = { messages: props.messages };
}
render () {
return(
<div>
@veelenga
veelenga / rails_rce.rb
Created February 27, 2017 11:28 — forked from postmodern/rails_rce.rb
Proof-of-Concept exploit for Rails Remote Code Execution (CVE-2013-0156)
#!/usr/bin/env ruby
#
# Proof-of-Concept exploit for Rails Remote Code Execution (CVE-2013-0156)
#
# ## Advisory
#
# https://groups.google.com/forum/#!topic/rubyonrails-security/61bkgvnSGTQ/discussion
#
# ## Caveats
#
@veelenga
veelenga / pre-commit
Created April 20, 2017 08:00
Git pre-commit hook to format Crystal code
#!/bin/sh
crystal tool format --check &> /dev/null
ret_code=$?
if [ 0 -ne $ret_code ]; then
crystal tool format
echo "Files formatted. Please review results and commit ;)"
exit $ret_code
else
@veelenga
veelenga / send.cr
Last active March 9, 2024 18:00
Implementation of send method in Crystal using macros and procs. Just a proof of concept.
class Object
macro inherited
@@methods = {} of String => Proc({{@type}}, Nil)
macro method_added(method)
\{% if method.visibility == :public %}
%key = \{{ method.name.stringify }}
@@methods[%key] = ->(obj : \{{@type}}) {
obj.\{{ method.name }}()
nil
@veelenga
veelenga / best_shards.cr
Last active December 8, 2018 21:57
Top 30 Shards created in 2017
require "http/client"
require "json"
module GithubAPI
API_URL = "https://api.github.com"
class Repo
JSON.mapping(
name: String,
html_url: String,