Skip to content

Instantly share code, notes, and snippets.

@net
net / render_in.ex
Last active Jul 7, 2016
Render Phoenix templates inside other templates
View render_in.ex
defmodule YourApp.RenderIn do
@moduledoc """
Renders a block inside another template.
## Usage
# template/page/page.html.eex
<div class="container">
<%= @yield %>
</div>
View random_bench.exs
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
View random.ex
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 Apr 7, 2016
Adding Bootstrap to Phoenix using NPM
View 1.js
// 1. Add Bootstrap as a dependency in package.json
{
...
"dependencies": {
...
"bootstrap": "~3.3.6"
}
}
@net
net / gist:2f615ca7da52f49b8069
Created Apr 19, 2015
itg.dark.tmTheme - Ruby Optimized
View gist:2f615ca7da52f49b8069
<?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 Aug 29, 2015
Astro-Phys.com API in Ruby
View gist:b43237844b8715448b11
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("&")