Skip to content

Instantly share code, notes, and snippets.

View Devalo's full-sized avatar
💭
:D

Stephan Bakkelund Valois Devalo

💭
:D
  • Tønsberg, Norway
View GitHub Profile
GIT
remote: git://github.com/leshill/handlebars_assets.git
revision: 03cb3ed3f44b1e2f669432a8d6aa346a4b25b6d2
specs:
handlebars_assets (0.22.0)
execjs (~> 2.0)
multi_json (~> 1.0)
sprockets (>= 2.0.0)
tilt (>= 1.2)
def delete(line)
tmp = Tempfile.new("todo_temp")
open(file, "r").each.with_index do |index, l|
tmp << l unless line == index.to_i
end
tmp.close
FileUtils.mv(tmp.path, file)
end
window.onload = function () {
var width = 800,
height = 800,
platformWidth = 200,
sprite,
platforms,
game = new Phaser.Game(800, 700, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
function preload() {
#In my schema
t.string "picture", default: [], array: true
#In my projects_controller.rb
def index
@projects = Project.friendly.all
end
def show
@project = Project.friendly.find(params[:id])
end
def index(conn, _params) do
case authenticate(conn) do
%Plug.Conn{halted: true} = conn ->
conn
conn ->
users = Repo.all(User)
render conn, "index.html", users: users
end
end
defmodule NaturalNums do
def print(1), do: IO.puts(1)
def print(n) do
print(n - 1)
IO.puts(n)
end
end
@Devalo
Devalo / auth.ex
Created May 24, 2016 20:09
Auth. When registering a new user, it checks if password and email is correct, and invoke login/2 which assigns :current_user and pipes through Guardian.Plug.sign_in. It raises error when using @current_user in views, saying assign @current_user not available in eex template.
defmodule Cvapp.Auth do
import Comeonin.Bcrypt, only: [checkpw: 2, dummy_checkpw: 0]
import Plug.Conn
def login(conn, user) do
conn
|> assign(:current_user, user)
|> Guardian.Plug.sign_in(user)
end
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Hello Cvapp!</title>
Prefix Verb URI Pattern Controller#Action
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
%{"batchcomplete" => "",
"query" => %{"normalized" => [%{"from" => "test", "to" => "Test"}],
"pages" => %{"11089416" => %{"extract" => "Test, TEST or Tester may refer to:\nTest (assessment), an assessment intended to measure the respondents' knowledge or other abilities\nMedical test, to detect, diagnose, or monitor diseases",
"ns" => 0, "pageid" => 11089416, "title" => "Test"}}}}