Skip to content

Instantly share code, notes, and snippets.

@ynonp
ynonp / day19.rb
Created December 19, 2017 20:26
advent of code day19
class Maze
attr_accessor :data
def initialize(stdin)
self.data = []
stdin.each_line do |line|
data.push(line.chomp.split(''))
end
end
defmodule Day9 do
def remove_bangs(line) do
Regex.replace(~r{!.}, line, "")
end
def count_garbage(line) do
IO.puts("Garbage Chars: ")
Regex.scan(~r{<.*?>}, line)
|> Enum.flat_map(&(&1))
|> Enum.reduce(0, fn(el, acc) -> acc + String.length(el) - 2 end)
defmodule Day5 do
def list_to_indexed_map(list) do
list
|> Enum.with_index(0)
|> Enum.map(fn({k,v}) -> {v,k} end)
|> Map.new
end
def next({ arr, ip }) do
try do
@ynonp
ynonp / day5.exs
Last active December 6, 2017 19:54
defmodule Day5 do
def next({ arr, ip }) do
try do
jump = elem(arr, ip)
diff = if jump >= 3, do: -1, else: 1
{
arr,
{
put_elem(arr, ip, jump + diff),
@ynonp
ynonp / cp.ex
Last active November 3, 2017 07:33
Elixir Cartesian Product Macro
@doc """
cp produces cartesian product from a list of lists, calling handler on each
result. Handler is expected to receive as many arguments as there are groups.
## Examples
iex> HelloWorld.cp([["10", "20"], ["a", "b", "c"], ["xx", "yy"]], fn(x, y,z) -> {x,y,z} end)
[{"10", "a", "xx"}, {"10", "a", "yy"}, {"10", "b", "xx"}, {"10", "b", "yy"},
{"10", "c", "xx"}, {"10", "c", "yy"}, {"20", "a", "xx"}, {"20", "a", "yy"},
{"20", "b", "xx"}, {"20", "b", "yy"}, {"20", "c", "xx"}, {"20", "c", "yy"}]
import sys
import os
if len(sys.argv) != 3:
print "Usage: %s <oldsuffix> <newsuffix>" % sys.argv[0]
sys.exit(1)
(_, oldsuffix,newsuffix) = sys.argv
for name in os.listdir("."):
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
options=1203<RXCSUM,TXCSUM,TXSTATUS,SW_TIMESTAMP>
inet 127.0.0.1 netmask 0xff000000
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
nd6 options=201<PERFORMNUD,DAD>
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether f4:0f:24:29:df:4d
@ynonp
ynonp / 01_syntax_review.md
Last active January 19, 2024 09:41
Python Exercises

Learn Python With Me

My (hebrew speaking) Python course is available online at: https://www.tocode.co.il/bundles/python

If you speak the language be sure to drop by and say hello.

Syntax Review

  1. Write a program that asks the user for a number (integer only) and prints the sum of its digits
@ynonp
ynonp / vimtips.md
Created April 4, 2017 09:11
my vim tips
  1. file navigation
  • √ open gvim on directory
  • √ open file qsize.h
  • √ use :e to open another file
  • √ use :e %:r.cpp to open corresponding cpp file
  • √ use gf to open included file
  • √ use Ctrl+O to jump back
  1. text objects
  • √ use ci(, ci{, ci[, ci" or ci' to replace contents of TO
"use strict";
var data = [];
function foo() {
var _loop = function _loop(i) {
data.push(function () {
return i;
});
};