Skip to content

Instantly share code, notes, and snippets.

(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;
package pl.allegro.tech.hermes.common.di;
import org.glassfish.hk2.api.DynamicConfiguration;
import org.glassfish.hk2.api.Factory;
import org.glassfish.hk2.utilities.Binder;
import org.glassfish.hk2.utilities.binding.ServiceBindingBuilder;
import org.glassfish.jersey.internal.inject.Injections;
@SuppressWarnings("unchecked")
public class InstantFactoryBinder {
@pjagielski
pjagielski / js-file-schema.cljs
Created February 11, 2015 19:07
Schema failing in phantomjs tests
(deftest file-validation
(s/defschema FileSchema
{:file (s/maybe (s/both js/File (s/pred (fn [f] (if f (< (.-size f) 1000000))) 'large-file)))})
(s/defn validated-file
[file :- [FileSchema]] 1)
(s/with-fn-validation
(is (= 1 (validated-file {:file nil})))))
[org.clojure/clojurescript "1.7.48"]
[org.clojure/core.async "0.1.346.0-17112a-alpha"]
[cljs-http "0.1.37"]
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [cljs-http.client :as http]
[cljs.core.async :refer [<! >! chan]]))
(defn rest-call []
(go
lein new duct clojure-web-app +example
lein repl
(go)
[ring/ring-json "0.3.1"]
[cheshire "5.1.1"]
[ring.middleware.json :refer [wrap-json-body wrap-json-response]]
[wrap-json-body {:keywords? true}]
@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')