Skip to content

Instantly share code, notes, and snippets.

@net
net / render_in.ex
Last active July 7, 2016 01:41
Render Phoenix templates inside other templates
defmodule YourApp.RenderIn do
@moduledoc """
Renders a block inside another template.
## Usage
# template/page/page.html.eex
<div class="container">
<%= @yield %>
</div>
@net
net / README.md
Last active July 7, 2016 01:40
Rendering Phoenix templates inside other templates
defmodule Random do
use Benchfella
@list ~w(a b c d e f g h i j k l m n o p)
@tuple List.to_tuple(@list)
bench "tuple" do
_ = elem(@tuple, :random.uniform(16) - 1)
:ok
end
defmodule Random do
@allowed_characters 'abcdefghijklmnopqrstuvwxyz1234567890'
def generate(length), do: generate(length, "")
def generate(0, acc), do: acc
def generate(length, acc), do: generate(length - 1, acc <> random_char)
def random_char, do: <<Enum.random(@allowed_characters)>>
end
@net
net / 1.js
Created April 7, 2016 02:26
Adding Bootstrap to Phoenix using NPM
// 1. Add Bootstrap as a dependency in package.json
{
...
"dependencies": {
...
"bootstrap": "~3.3.6"
}
}
@net
net / gist:2f615ca7da52f49b8069
Created April 19, 2015 21:15
itg.dark.tmTheme - Ruby Optimized
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>author</key>
<string>@itg</string>
<key>colorSpaceName</key>
<string>sRGB</string>
<key>name</key>
<string>itg.dark</string>
@net
net / gist:b43237844b8715448b11
Last active August 29, 2015 14:15
Astro-Phys.com API in Ruby
require 'open-uri'
require 'json' # For parsing the response into a hash
# As defined here http://www.astro-phys.com/api
call = 'coefficients' # note: '/api/de406/' is not needed
parameters = ['bodies=sun'] # e.g. ['bodies=venus', 'type=m']
# Converts parameters to query string
unless parameters.empty?
parameters = parameters.join("&")