Skip to content

Instantly share code, notes, and snippets.

@pjagielski
pjagielski / SpringSecuritySigninService.groovy
Created April 10, 2012 15:28
SpringSecuritySigninService
class SpringSecuritySigninService extends GormUserDetailsService {
void signIn(User user) {
def authorities = loadAuthorities(user, user.username, true)
def userDetails = createUserDetails(user, authorities)
SecurityContextHolder.getContext().setAuthentication(
new UsernamePasswordAuthenticationToken(userDetails, null,
userDetails.authorities))
}
@pjagielski
pjagielski / GoogleAuthService.groovy
Created April 10, 2012 15:44
GoogleAuthService
class GoogleAuthService extends GrailsOAuthService {
@Override
OAuthService createOAuthService(String callbackUrl) {
def builder = createServiceBuilder(GoogleApi20,
grailsApplication.config.auth.google.key as String,
grailsApplication.config.auth.google.secret as String,
callbackUrl)
return builder.grantType(OAuthConstants.AUTHORIZATION_CODE)
.scope('https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email')
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 / 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);
}
(ns kafka.core
(:require
[clojure.core.async :as async]
[clj-kafka.core :refer [with-resource]]
[clj-kafka.producer :refer [producer send-message message]]
[clj-kafka.consumer.zk :refer [consumer messages shutdown]])
(:gen-class))
(def p (producer {"metadata.broker.list" "localhost:9092"
"serializer.class" "kafka.serializer.DefaultEncoder"
(ns file-counter.core
(:require [clojure.core.async :refer :all])
(:gen-class))
(defn count-files [count-chn path-chn path]
(doseq [file (.listFiles (java.io.File. path))]
(if (.isFile file)
(println (.getAbsolutePath file))
(>!! path-chn (.getAbsolutePath file)))))
@groovy.lang.Grab("com.netflix.rxnetty:rx-netty:0.3.14")
import io.netty.buffer.ByteBuf
import io.reactivex.netty.RxNetty
import io.reactivex.netty.protocol.http.server.HttpServer
import io.reactivex.netty.protocol.http.server.HttpServerPipelineConfigurator
import io.reactivex.netty.protocol.http.server.HttpServerRequest
import io.reactivex.netty.protocol.http.server.HttpServerResponse
import io.reactivex.netty.protocol.http.server.RequestHandler
import rx.functions.Func1
package pl.allegro.tech.hermes.common.di;
import org.glassfish.hk2.api.DynamicConfiguration;
import org.glassfish.hk2.utilities.Binder;
import org.glassfish.hk2.utilities.binding.ScopedBindingBuilder;
import org.glassfish.jersey.internal.inject.Injections;
@SuppressWarnings("unchecked")
public class InstantBinder {
ScopedBindingBuilder builder;