Skip to content

Instantly share code, notes, and snippets.

View shankardevy's full-sized avatar

Shankar Dhanasekaran shankardevy

View GitHub Profile
event = %Ical.Event{}
lines = String.split(text, line_break_regex)
Enum.reduce(lines, fn(line, event) ->
updates = Regex.named_captures(line_regex, line)
event = update_event(event, updates)
end)
IO.puts event
a = 5
Enum.each [1,2,3], fn x -> a = x * a end
IO.puts a # returns 5, while I expect 15, the last iterated value
@shankardevy
shankardevy / gist:4eba0fb45d0dd02af407
Created March 9, 2015 15:53
Check for incorrect usage of ":" in mix phoenix.gen.resource
defmodule Mix.Tasks.Phoenix.Gen.Resource do
use Mix.Task
alias Phoenix.Naming
@shortdoc "Generates resource files"
@moduledoc """
Generates a Phoenix resource.
mix phoenix.gen.resource User users name:string age:integer
@shankardevy
shankardevy / gist:a15fab0f056d9ac05b4a
Created March 6, 2015 19:16
Generators for Phoenix controllers
defmodule Mix.Tasks.Phoenix.Gen.Controller do
use Mix.Task
import Mix.Generator
@shortdoc "Generates a new controller"
@moduledoc """
Generates a new controller.
@shankardevy
shankardevy / gist:d2cf0f607a81c55210e1
Created March 6, 2015 18:40
Generator for phoenix controller
defmodule Mix.Tasks.Phoenix.Gen.Controller do
use Mix.Task
import Mix.Generator
@shortdoc "Generates a new controller"
@moduledoc """
Generates a new controller.
@shankardevy
shankardevy / gist:c86814ad9c82310175e2
Last active August 29, 2015 14:16
sample migration
defmodule MyApp.Repo.Migrations.CreateTalks do
use Ecto.Migration
def up do
"CREATE TABLE talks (
id serial primary key,
title varchar(255),
timestamp integer) "
end
@shankardevy
shankardevy / gist:32ac39666821be55f820
Last active August 29, 2015 14:16
Alternate function signature for IO.inspect
# Currently we have these two function signatures for handling `IO.inspect "string"`
# https://github.com/elixir-lang/elixir/blob/master/lib/elixir/lib/io.ex#L191-L205
def inspect(item, opts \\ []) do
inspect group_leader(), item, opts
end
def inspect(device, item, opts) when is_list(opts) do
opts = struct(Inspect.Opts, opts)
iodata = Inspect.Algebra.format(Inspect.Algebra.to_doc(item, opts), opts.width)
puts device, iodata
@shankardevy
shankardevy / gist:1abea2fe7373c13f7e4c
Created January 20, 2015 20:00
Understaning enum.map_reduce
<%= Enum.map_reduce @messages, initial_value, fn current, prev -> %>
<li>
<% if current.type != prev.type do %>
<span class="msg-type"><%= current.type %></span>
<% end %>
<br/><%= current.msg %>
</li>
<% end |> elem(0) %>
@shankardevy
shankardevy / gist:e33ba78b45b4f70e2515
Created January 20, 2015 19:50
understaning elixir chunk
<%= for [prev,next] <- Enum.chunk(@messages, 2, 1) do %>
<li>
<%= if next.type != current.type do %>
<span class="msg-type"><%= current.type %></span>
<% end %>
<br/><%= current.msg %>
</li>
<% end %>
@shankardevy
shankardevy / gist:cfe77acd9fe7bded116c
Last active August 29, 2015 14:12
sample mpd file
<?xml version="1.0" encoding="UTF-8"?>
<MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:mpeg:dash:schema:mpd:2011"
xmlns:xlink="http://www.w3.org/1999/xlink"
xsi:schemaLocation="urn:mpeg:DASH:schema:MPD:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd"
profiles="urn:mpeg:dash:profile:isoff-live:2011"
type="static"
mediaPresentationDuration="PT9M56.458S"
minBufferTime="PT1.5S">
<ProgramInformation>