Skip to content

Instantly share code, notes, and snippets.

View shankardevy's full-sized avatar

Shankar Dhanasekaran shankardevy

View GitHub Profile
@shankardevy
shankardevy / anonymous-gist.el
Created October 8, 2014 17:12
testing yagist
(require 'init-git)
(require-package 'yagist)
(require-package 'github-browse-file)
(require-package 'bug-reference-github)
(add-hook 'prog-mode-hook 'bug-reference-prog-mode)
(when (eval-when-compile (> emacs-major-version 23))
(require-package 'github-clone)
(require-package 'magit-gh-pulls))
@shankardevy
shankardevy / gist:c00a88468b2027185ac8
Created October 31, 2014 12:16
Restrict file upload by extension on html input tags
// HTML
// <input type="file" data-allowed-files="pdf|jpeg"/>
$('#file').on('change', function(e){
var types = new RegExp('(\\.)('+ $(e.target).data('allowed-files') + ')$', 'i');
if(!types.test(this.value)
alert('not allowed');
this.value='';
}
@shankardevy
shankardevy / gist:52dcacfdcb6c812da284
Last active August 29, 2015 14:10
ISO3 country code as php array
<?php
$countries = array(
"ABW" => "Aruba",
"AFG" => "Afghanistan",
"AGO" => "Angola",
"AIA" => "Anguilla",
"ALA" => "Åland Islands",
"ALB" => "Albania",
"AND" => "Andorra",
@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>
@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: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: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: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: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: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.