Skip to content

Instantly share code, notes, and snippets.

Oliver Severin Mulelid-Tynes olivermt

  • Microsoft / OMT Tech AS
  • Hamar, Norway
View GitHub Profile
View behavior.ex
defmodule RestAuth.RestAuthHandler do
use Behaviour
@doc "Loads a user from the database, will be used by `get_user_roles/1` function and ´get_user_metadata/1` functions"
defcallback load_user(username :: String.t, password :: String.t) :: Any
@doc "Fetches user roles from user object"
defcallback get_user_roles(user :: Any) :: []
@doc "Returns default set of roles, for example `[\"ROLE_USER\"]`."
View gist:8a8a3094f5e16338ba8b
iex(15)> {:ok,payload} = Poison.encode %{"user_id" => 1, "roles" => ["admin", "user"], "metadata" => %{"foo" => "bar"}}
{:ok,
"{\"user_id\":1,\"roles\":[\"admin\",\"user\"],\"metadata\":{\"foo\":\"bar\"}}"}
iex(16)> token = Phoenix.Token.sign(Core.Endpoint, "bar", payload)
"g3QAAAACZAAEZGF0YW0AAAA/eyJ1c2VyX2lkIjoxLCJyb2xlcyI6WyJhZG1pbiIsInVzZXIiXSwibWV0YWRhdGEiOnsiZm9vIjoiYmFyIn19ZAAGc2lnbmVkbgYAaGwXbk8B--7TCEz5KiWYV4F8lPc5dbJjbpsAE="
iex(17)> {:ok,decoded} = Phoenix.Token.verify(Core.Endpoint, "bar", token)
{:ok,
"{\"user_id\":1,\"roles\":[\"admin\",\"user\"],\"metadata\":{\"foo\":\"bar\"}}"}
iex(18)>
View gist:ccea618ca92d5224343c
defmodule Core.OpensipsClusterView do
use Core.Web, :view
def render("index.json", %{opensips_clusters: opensips_clusters}) do
%{data: render_many(opensips_clusters, Core.OpensipsClusterView, "opensips_cluster.json")}
end
def render("show.json", %{opensips_cluster: opensips_cluster}) do
%{data: render_one(opensips_cluster, Core.OpensipsClusterView, "opensips_cluster.json")}
end
View test.js
/*--- QUERY ---*/
self.query = {
projects: ko.observableArray(<%= projectIDs %>), //we start with all projects checked
outcrops: ko.observableArray([]),
grossDepositionalEnvironment: ko.observable(""),
depositionalEnvironment: ko.observable(""),
mainClimate: ko.observableArray([]),
depositionalSubEnvironment: ko.observable(""),
architecturalElement: ko.observable(""),
//filters
View gist:9972302
def crit = Teacher.createCriteria()
def teacherList = crit.list {
classes {
eq('id', classInstance.id)
}
}
View example.php
<?php
//============================================================+
// File name : example_001.php
// Begin : 2008-03-04
// Last Update : 2013-05-14
//
// Description : Example 001 for TCPDF class
// Default Header and Footer
//
// Author: Nicola Asuni
View gist:e998a66fef1970055c30
/* jshint node: true */
'use strict';
var gulp = require('gulp'),
g = require('gulp-load-plugins')({lazy: false}),
noop = g.util.noop,
es = require('event-stream'),
queue = require('streamqueue'),
lazypipe = require('lazypipe'),
stylish = require('jshint-stylish'),
View sda.js
angular.module('safariFront.common', ['safariFront.commonServices'])
.controller('RegistrationModalController', ['$scope', function($scope) {
$scope.companies = {} //will show you new fancy rest thing later
}])
.controller('BodyController',['$scope', 'LoginService', function($scope, LoginService) {
'use strict';
$scope.topTitle = "Home";
$scope.user = LoginService.getUser();
View Page.groovy
package no.cipr.safari.auxiliary
class Page {
String pageName, title, content
Boolean secured
static constraints = {
pageName(unique: true, blank: false)
View foo.groovy
@Secured('IS_AUTHENTICATED_ANONYMOUSLY')
def test() {
respond UserRole.withCriteria {
role {
eq('authority', 'ROLE_COMPANY_ADMIN')
}
}
}
You can’t perform that action at this time.