This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def render("show.json", %{data: data}) do | |
| %{ | |
| id: data.id, | |
| name: data.name, | |
| title: String.capitalize!(data.name) | |
| } | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule MyApp.CommentView do | |
| use MyApp.Web, :view | |
| @attributes ~W(id name inserted_at) | |
| def render("show.json", data: data) when is_list(data) do | |
| for c <- data do | |
| render("show.json", data: data) | |
| end | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule MyApp.MyModelController do | |
| use MyApp.Web, :controller | |
| plug :action | |
| def show(conn, params) do | |
| json conn, Repo.get!(MyModel, params[:id]) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import random | |
| obliqstrats = ['(Organic) machinery', '(This Line Intentionally Left Blank)', 'A line has two sides', 'A very small object -Its centre', 'Abandon desire', 'Abandon normal instructions', 'Accept advice', 'Accretion', 'Adding on', 'Allow an easement (an easement is the abandonment of a stricture)', 'Always first steps', 'Always give yourself credit for having more than personality', 'Always the first steps', 'Are there sections? Consider transitions', 'Ask people to work against their better judgement', 'Ask your body', 'Assemble some of the elements in a group and treat the group', 'Back up a few steps. What else could you have done?', 'Balance the consistency principle with the inconsistency principle', 'Be dirty', 'Be extravagant', 'Be less critical more often', 'Breathe more deeply', 'Bridges -build -burn', 'Call your mother and ask her what to do.', 'Cascades', 'Change ambiguities to specifics', 'Change instrument roles', 'Change nothing and continue with immaculate c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def save_and_after_commit(&block) | |
| Sequel::Model.db.transaction do | |
| Sequel::Model.db.after_commit(&block) | |
| self.save | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def index(conn, %{"event" => "true"}) do | |
| conn = conn | |
| |> put_resp_content_type("text/event-stream") | |
| |> send_chunked(200) | |
| {:ok, conn} = chunk(conn, ["data: ", JSON.encode!(Thermostat.Data.get()), "\n\n"]) | |
| Phoenix.Topic.subscribe self, "data" | |
| data_updated(conn) | |
| end | |
| defp data_updated(conn) do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Simple Phoenix authentication plug | |
| # | |
| # - based on Plug's session store | |
| # - redirects unauthenticated requests to login page "/login/<request url>" | |
| # - /static/... requests are not authenticated | |
| # - authentication is valid as long as session is valid (you can change this behaviour easily) | |
| # Because we need session to be fetched BEFORE this plug, we must put this to router.ex: | |
| #---------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| gem 'rest-client', '~> 1.6.7' | |
| gem 'nokogiri' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Roadcast.Google.Polyline do | |
| use Bitwise | |
| #TODO Work on this code | |
| def decode(polyline) when is_binary(polyline) do | |
| decode(lc <<x>> inbits polyline, do: x - 63) | |
| end | |
| def decode(coll) when is_list(coll) do | |
| coll |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| '''Provides utility functions for encoding and decoding linestrings using the | |
| Google encoded polyline algorithm. | |
| ''' | |
| def encode_coords(coords): | |
| '''Encodes a polyline using Google's polyline algorithm | |
| See http://code.google.com/apis/maps/documentation/polylinealgorithm.html | |
| for more information. | |