Skip to content

Instantly share code, notes, and snippets.

class AuthController {
SpringSecuritySigninService springSecuritySigninService
def signin = {
GrailsOAuthService service = resolveService(params.provider)
if (!service) {
redirect(url: '/')
}
OAuthProfile getProfile(OAuthService authService, Token accessToken) {
OAuthRequest request = new OAuthRequest(Verb.GET, 'https://www.googleapis.com/oauth2/v1/userinfo')
authService.signRequest(accessToken, request)
def response = request.send()
def user = JSON.parse(response.body)
def login = "${user.given_name}.${user.family_name}".toLowerCase()
new OAuthProfile(username: login, email: user.email, uid: user.id, picture: user.picture)
@pjagielski
pjagielski / LinkStatistics.groovy
Created October 5, 2012 14:10
Projections Grails
class LinkStatistics {
static belongsTo = [link: Link]
Integer score
Date dateCreated
static mapping = {
table("v_link_statistics")
link(fetch: FetchMode.EAGER)
version(false)
@pjagielski
pjagielski / api.clj
Last active November 23, 2015 19:43
clojure-web
(ns jinkubator.endpoint.api
(:require [compojure.api.sweet :refer :all]
[ring.util.http-response :refer [ok]]
[schema.core :as s]))
(s/defschema Message
{:message s/Str})
(s/defschema MessageList
[Message])
@pjagielski
pjagielski / Sender.java
Last active January 2, 2016 17:59
Fast vert.x sender
import org.vertx.java.core.Handler;
import org.vertx.java.core.VoidHandler;
import org.vertx.java.core.eventbus.Message;
import org.vertx.java.platform.Verticle;
public class Sender extends Verticle {
public void start() {
send(0);
}
@pjagielski
pjagielski / count-on-me.rb
Created May 14, 2016 20:07
Count on me supersaw
use_bpm 130
ch1 = [62,65,69]
ch2 = [63,67,70]
ch3 = [65,69,72]
ch4 = [67,70,74]
live_loop :saws do
use_synth :supersaw
with_synth_defaults sustain_level: 0.75, release: 1.25, cutoff: 130, amp: 1.5 do
use_bpm 130
samps = "path_to_breaks" ## download from http://www.junglebreaks.co.uk/breaks.html
ch1 = [61,68,78]
ch2 = [61,68,76]
ch3 = [64,71,76]
ch4 = [59,66,75]
ch5 = [59,66,76]
ch6 = [57,64,76]
(ns worldcup.matches
(:require
[clj-http.client :as http]))
(def api-root "https://worldcup.sfg.io")
(defn get-all-matches []
(->
(http/get (str api-root "/matches") {:as :json})
:body))
(->> lst
(map op1)
(map op2)
(filter p1)
first)
lst.stream()
.map(op1)
.map(op2)
.filter(p1)
(defn goal? [e]
(let [type (:type_of_event e)]
(or (= "goal" type)
(= "goal-penalty" type)
(= "goal-own" type))))