Skip to content

Instantly share code, notes, and snippets.

View alco's full-sized avatar
🇺🇦

Oleksii Sholik alco

🇺🇦
View GitHub Profile
@alco
alco / ripple.frag
Created July 8, 2012 11:52
Ripple effect for GLSL
// simple fragment shader
// 'time' contains seconds since the program was linked.
uniform float time;
uniform sampler2D tex;
uniform sampler2D tex2;
float radius = .5;
@alco
alco / port.ex
Last active June 28, 2023 19:39
def open_port(executable, args) do
Port.open({:spawn_executable, executable}, [:stream, :binary, {:args, args}, :use_stdio, :stderr_to_stdout, :exit_status])
end
def process_port(port) do
case collect_output(InternalData[port: port], []) do
{status, data} -> Result[status: status, output: to_string(data)]
end
end
@alco
alco / gist:2165064
Created March 22, 2012 22:20
Count the number of non-blank SLOC in an Elixir project
git ls-files | egrep '\.erl|\.ex[s]$' | xargs cat | sed '/^$/d' | wc -l
defmodule View do
defrecord Page, [templates: []]
defmacro __using__(_) do
template = """
<%= for template <- page.templates do %>
<%= template.id %> ::
<% end %>
<%= if true do %>
@alco
alco / re.ex
Created September 4, 2013 09:23
iex(8)> Regex.run %r/^~(\d)+\.\.[0 ]B$/, "~4..0B"
["~4..0B", "4"]
iex(9)> Regex.run %r/^~(\d)+\.\.[0 ]B$/, "~4..0B", capture: :groups
** (ArgumentError) regex was not compiled with g
/Users/alco/Documents/git/elixir/lib/elixir/lib/regex.ex:134: Regex.run/3
erl_eval.erl:569: :erl_eval.do_apply/6
src/elixir.erl:138: :elixir.eval_forms/3
iex(9)> Regex.run %r/^~(\d)+\.\.[0 ]B$/g, "~4..0B", capture: :groups
[]
@alco
alco / macro_list.ex
Last active September 25, 2022 19:56
defmodule L do
# lc x inlist [0, 1], y inlist [:a, :b], do: {x, y}
defmacro do_list(list) do
args = 1..length(list)
|> Enum.map(fn x -> binary_to_atom(<<?a + x :: utf8>>) end)
|> Enum.map(fn x -> {x, [], :Elixir} end) # this creates AST nodes for variables
pairs = Enum.zip(args, list)
|> Enum.map(fn {v, lst} ->
quote do
iex> use PipeInspect
nil
iex> "hello" |> String.reverse |> String.upcase |> String.downcase
"olleh"
"OLLEH"
"olleh"
defmodule TimeFormat do
def format(seconds) do
hours = div(seconds, 3600)
remainder = rem(seconds, 3600)
minutes = div(remainder, 60)
seconds = rem(remainder, 60)
format(hours, minutes, seconds)
end
defp format(0, minutes, seconds), do: "#{minutes}:#{pad(seconds)}"

Keybase proof

I hereby claim:

  • I am alco on github.
  • I am alco (https://keybase.io/alco) on keybase.
  • I have a public key whose fingerprint is 4C14 8955 BB20 D94E 2483 4392 E5B2 32A7 2D91 58F1

To claim this, I am signing this object:

@alco
alco / glob_match.cc
Created February 20, 2012 14:41
A translation of Python's fnmatch function into C++
#include <string>
#include "regex.h"
/*
* Return a new string with all occurrences of 'from' replaced with 'to'
*/
std::string replace_all(const std::string &str, const char *from, const char *to)
{
std::string result(str);