Re: Clojure On Java Friendly Microcontrollers, Beaglebone, etc

2013-09-02 Thread Nurullah Akkaya
I have not played with Java friendly micros but Clojure works on the
beagle/pi. As for building robots using clojure,

 - Our software for our Robocup team is all Clojure except couple
   hundred lines of C for the firmware running on the AVRs. All heavy
   lifting is done on the PC, AVRs only deal with interfacing with the
   motor controllers, kicking circuit etc. [5] is our old code from
   2012.

 - I was working on a blob tracking nerf gun which I never
   finished. That was using beagleboard for vision and an Arduino for
   controlling the servos. I never finished it and I did port it to
   gambit scheme for some reason I don't remember.

   It used, vision[1] to find/track blobs and cloudino[2] to talk to
   Arduino which controlled the servos of the gun.

   When using beagle/pi you are going to need a seperate
   microcontroller to deal with real time stuff, PWM generation etc.

Another option I am playing with right now is actually putting an
android phone on the robot.

 - I did port a simple autopilot (following a set of waypoints using,
   GPS from the phone and IMU from the AR Drone) to android using lein
   droid [3]. Taped the phone on top of an Ar Drone. It barely worked
   in the lab with mock GPS when there was no wind but the phone is
   too heavy for AR Drone but this scheme would work with a more power
   full quad.

 - I am applying the same idea to a boat now. Android phone on the
   boat, a webapp (http-kit/compojure/hiccup) for getting telemetry
   and setting way points over 3G, usb-serial-for-android[4] for
   talking to arduino which handles interfacing with the motor
   controllers, phone GPS/IMU for navigation.

 [1] https://github.com/nakkaya/vision
 [2] https://github.com/nakkaya/clodiuno
 [3] https://github.com/clojure-android/lein-droid
 [4] http://code.google.com/p/usb-serial-for-android/
 [5] http://dropbox.nakkaya.com/neu-islanders.pdf

Best,

On Mon, Sep 2, 2013 at 6:21 AM, Jeremy Wright wright...@gmail.com wrote:
 Here are some updates on my own research.

 This post is a little over a year old, but has the type of information on
 the BeagleBone I'm looking for. It covers doing some simple I/O using
 Clojure. The author states that he's unsure what he's doing on the hardware
 side of things, but it's a start.
 This post says it's easy to get Clojure working on the Beagleboard, but is a
 couple of years old and doesn't give too much detail. I do like that the
 author does some benchmarking that could be adapted to the BeagleBone Black
 though.
 This post is about a year old, and gives a benchmark comparison of OpenJDK
 vs Oracle's Embedded JRE on a BeagleBone.
 Videos of Kevin Downey (less than a year old) showing a robot using Clojure
 on a BeagleBone. He gives some insight into how to make using the Bone's I/O
 system in Clojure a little easier.

 Video 1 of 3
 Video 2 of 3
 Video 3 of 3

 Kevin Downey's Beaglebone robot code on Github.
 Kevin Downey mentioned clojure-jna which should make working with native
 code (to do I/O) on the Bone a little easier. The clojure-jna code on GitHub
 is about 4 years old though, and I may have read something about a newer
 replacement on this mailing list. I can't remember for sure though.

 That's what I've found so far. The information has some age on it and is
 focused on the older BeagleBone and Beagleboard. It's good information to
 get started with though I think.

 On Saturday, August 31, 2013 11:13:59 PM UTC-4, Jeremy Wright wrote:

 I recently watched Carin Meier's OSCON talk The Joy of Flying Robots with
 Clojure and it made me wonder about Clojure on embedded systems. A quick
 search on this list didn't turn up much so I thought I'd ask. How much work
 has been done with Clojure on either Java friendly microcontroller systems
 (i.e. Systronix), or on something like a Beaglebone or Beagleboard? I'm very
 new to Clojure, so I don't yet understand the challenges that Clojure would
 face trying to run on a system that may not support all the JVM's features.

 Any thoughts on this? Any links you can give me on what's been/being done?

 Thanks.

 --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.



-- 
Nurullah Akkaya
http://nakkaya.com

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to 

Re: Compiling Clojure security knowledge

2013-09-02 Thread abp


 clojars uses 
 https://github.com/ato/clojars-web/blob/master/src/clojars/web/safe_hiccup.clj
  
 which automatically escapes. 


But that double escapes attribute values if you don't put them in raw-calls.

On Monday, September 2, 2013 6:32:59 AM UTC+2, Ivan Kozik wrote:

 On Sun, Sep 1, 2013 at 7:06 PM, Vincent Ambo taz...@gmail.comjavascript: 
 wrote: 
  * How and where do we prevent XSS attacks? Do we have templating engines 
  that escape things unless told otherwise, or - if not - do these 
 features 
  exist in the form of a helper function? If yes, where? (And so on...) 

 clojars uses 
 https://github.com/ato/clojars-web/blob/master/src/clojars/web/safe_hiccup.clj
  
 which automatically escapes. 

 Ivan 


-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Clojure for the Brave and True, an online book for beginners

2013-09-02 Thread Daniel Higginbotham
Hi all,

I've been putting together http://www.braveclojure.com/ and would love 
feedback. I've tried to make it entertaining and super beginner-friendly.

Thanks!
Daniel

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


evaluation order in loading file/project (with leiningen)

2013-09-02 Thread Erebus Mons
Hi,

I am trying to find my way around clojure and leiningen. I created a project 
with lein new, and up to now, all my code is in the src/../core.clj file

I have a function that defines functions based on what is read in from a 
csv-file, in the following format:

(defn define-all-properties
  []
  (for [ stuff ]
...
(eval `(defn ~name [arg#]
  (...))

I then do

(define-all-properties)

Here is my problem: I have also tried to define in the same file functions 
based on those created by *define-all-properties*, like the following:

(defn obstruent? [sound]
  (or (stop? sound)
  (fricative? sound)))

When I load the core file for the first time, there is an error message, 
because the function stop? is not yet defined. I understand - I think - why 
this is so. After loading the core file for the first time, I have to 
evaluate (define-all-properties), and at the next load for the file, there 
is no error anymore.

While I can do that by hand with nrepl, the problem is that when I define 
tests in the tests directory, lein test also fails with the same error 
message.

I assume that making a makro out of *define-all-properties* is not the way 
to go, because it depends on the reading of a file, which should not yet be 
done at compile time (this may be a false assumption; in any way, simply 
changing the defn to a defmacro does not seem to resolve the issue).

Is there a (recommended) way of enforcing that a certain function has 
already been evaluated  when another one is called?

I thought I might try to create another file containing the function-
defining function, and then load it from the core file. It would be easier 
if in Leiningen, this could be specified (but I didn't find any reference to 
load order). 

Or is there a way of adding a hook to a function, specifying at which time 
it needs to be defined?

I hope that I am being clear here...

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Java Metadata Wrapper

2013-09-02 Thread Cedric Greevey
On Sun, Sep 1, 2013 at 9:58 AM, Colin Jones trptco...@gmail.com wrote:

 I thought of protocols initially here too, but protocols just define
 functions, so where would the data live that you want as metadata?

 A closure over the data? This implies extending the protocol on a
 per-instance basis, which afaik doesn't exist (cljs design work aside
 http://dev.clojure.org/display/design/specify+i.e.+reify+for+instances).

 Some global map? We can't key on arbitrary java objects since the hashcode
 can change. Is there a key that will work?


WeakIdentityHashMap is lacking from java.util but there are several
third-party implementations.

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Clojure On Java Friendly Microcontrollers, Beaglebone, etc

2013-09-02 Thread Jeremy Wright
Thanks for the great information nakkaya. You've worked on some very cool 
things.

About the Java friendly micros - I mentioned Systronix, but it looks like 
that community and product line may be dormant or even abandoned. There 
haven't been any posts to their Google Groups or many of their forums for 
at least a year.

What about using the built-in I2C interface on the BeagleBone/BeagleBoard 
to handle the I/O? For example, something like this 
producthttp://www.robotshop.com/seeedstudio-grove-i2c-motor-driver.html?utm_source=googleutm_medium=baseutm_campaign=josfrom
 Robot Shop. As you mentioned, you're still offloading the real-time 
work onto another microcontroller (ATmega8L), but by using I2C bus devices 
you can expand your control system as needed without an Arduino. Would 
there be any disadvantages to doing this?

On Saturday, August 31, 2013 11:13:59 PM UTC-4, Jeremy Wright wrote:

 I recently watched Carin Meier's OSCON talk The Joy of Flying Robots with 
 Clojure http://www.youtube.com/watch?v=Ty9QDqV-_Ak and it made me 
 wonder about Clojure on embedded systems. A quick search on this list 
 didn't turn up much so I thought I'd ask. How much work has been done with 
 Clojure on either Java friendly microcontroller systems (i.e. 
 Systronixhttp://www.systronix.com/), 
 or on something like a Beaglebone or Beagleboard? I'm very new to Clojure, 
 so I don't yet understand the challenges that Clojure would face trying to 
 run on a system that may not support all the JVM's features.

 Any thoughts on this? Any links you can give me on what's been/being done?

 Thanks.


-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: lazy seq from reducers with core.async

2013-09-02 Thread Jozef Wagner
Another nice abuse of core.async is for the implementation of 
multi-reducible collections. Here is the implementation of interleave 
accepting/producing reducibles. Slower than lazy seqs, but hey, you can 
feed it with any reducible coll. BTW anybody knows the status of multi 
reducibles? Are they being worked on?

 (defn interleave* [ colls]
(reify clojure.core.protocols.CollReduce
  (coll-reduce [this f1]
(clojure.core.protocols/coll-reduce this f1 (f1)))
  (coll-reduce [_ f1 init]
(let [NIL (Object.)
  encode-nil #(if (nil? %) NIL %)
  decode-nil #(if (identical? NIL %) nil %)
  send-fn (fn [coll]
(let [c (chan)]
  (thread (reduce (fn [r v] (!! c (encode-nil v))) nil 
coll)
  (close! c)) 
  c))
  chans (doall (map send-fn colls))]
  (loop [val init
 s (cycle chans)]
(let [c (first s)
  x (!! c)]
  (if-not (nil? x)
(let [x (decode-nil x)
  ret (f1 val x)]
  (if (reduced? ret)
@ret
(recur ret (rest s
val)))

(reduce + (clojure.core.reducers/take 100
  (interleave* (range)
   (clojure.core.reducers/map inc (range)


https://gist.github.com/wagjo/6335189

JW

On Sunday, August 25, 2013 7:47:14 PM UTC+2, Jozef Wagner wrote:

 Hi,

 A distinctive feature of reducers is that reducing is a one-shot thing. 
 The common understanding is that reducers are fast for cases where you want 
 to process whole collection at once, but for infinite and lazy seqs, you 
 have to use good old seqs.

 With core.async, it is now easy to create a transformation which produces 
 lazy seq from any reducible collection.

   (defn lazy-seq*
 [reducible]
 (let [c (chan)
   NIL (Object.)
   encode-nil #(if (nil? %) NIL %)
   decode-nil #(if (identical? NIL %) nil %)]
   (thread
(reduce (fn [r v] (!! c (encode-nil v))) nil reducible)
(close! c))
   (take-while (complement nil?) (repeatedly #(decode-nil (!! c))
  
   (def s (lazy-seq* (clojure.core.reducers/map inc (range
  
   (first s)
  
   (take 100 s)

 This approach can be also extended to produce chunked seqs and chan buffer 
 can also be used to further tune the performance.

 JW



-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[ANN] riddley: code-walking without caveats

2013-09-02 Thread Zach Tellman
When I announced Proteus [1], it was rightfully pointed out that it didn't 
play nicely with macros which rely on env, as well as a few forms like 
'letfn' that I hadn't explicitly handled.  This flaw has been shared by 
pretty much every library of this sort, and since this is a problem I've 
half-solved two or three times already, I figured something more general 
and lasting was in order.

The resulting library is called Riddley [2].  For obvious reasons, I've 
named it after a book which is written entirely in a barely-readable pidgin 
dialect. While there may be lingering issues, it's good enough to replace 
the code-walking mechanism in Proteus, which I think makes it the best game 
in town right now.  Bug reports and pull requests are welcome.

Zach

[1] 
https://groups.google.com/forum/#!searchin/clojure/proteus/clojure/7HNNiJJTte4/iMBWn8p6tZAJ
[2] https://github.com/ztellman/riddley

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: evaluation order in loading file/project (with leiningen)

2013-09-02 Thread Armando Blancas


 I assume that making a makro out of *define-all-properties* is not the way 
 to go, because it depends on the reading of a file, which should not yet 
 be 
 done at compile time (this may be a false assumption;...).

 Seems to me this is the key to how you'd construct your program. The csv 
file could be an artifact of your build, in which case it's got to be read 
at compile time and it's then when you make a top-level call to 
(define--all-properties) allowing you to compile (stop?), etc. If the file 
is input to your program, all this must be done at runtime: reading the 
file, calling (define-all-properties) and then loading any other code that 
depends on that, in effect making your program extensible.

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: evaluation order in loading file/project (with leiningen)

2013-09-02 Thread Waldemar
Hi Erebus,

I am also new so I'm also just guessing.

What if you execute the code inside define-all-properties directly without 
wrapping it in a function?

Am 02.09.2013 um 19:04 schrieb Erebus Mons erebus.m...@gmail.com:

 (defn define-all-properties
  []
  (for [ stuff ]
...
(eval `(defn ~name [arg#]
  (...))
 
 I then do
 
 (define-all-properties)
 
 Here is my problem: I have also tried to define in the same file functions 
 based on those created by *define-all-properties*, like the following:
 
 (defn obstruent? [sound]
  (or (stop? sound)
  (fricative? sound)))

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Compiling Clojure security knowledge

2013-09-02 Thread Nelson Morris
On Mon, Sep 2, 2013 at 6:25 AM, abp abp...@gmail.com wrote:

 clojars uses https://github.com/ato/**clojars-web/blob/master/src/**
 clojars/web/safe_hiccup.cljhttps://github.com/ato/clojars-web/blob/master/src/clojars/web/safe_hiccup.clj

 which automatically escapes.


 But that double escapes attribute values if you don't put them in
 raw-calls.


Yes, it double escapes attributes. In addition, doctype helpers like
`html5` might need to be redefined to use a `(raw ...)` for some parts.
There might be other functions where a `(raw ...)` is needed. The changes
in that file have proven sufficient for clojars, and I much prefer the
escape by default semantics, but more work might be needed for others.

Additionally, CSRF protection can happen with ring-anti-forgery.  The
clojars source link above includes a `form-to` function that is a
replacement for hiccup's `form-to` that adds the token on any
non-get/non-head forms.  It does require adding anti-forgery to the
middleware stack.



Several of Yesod's responses to other items on the list are humorous in
there vagueness, but in my experience for clojure:

1.Injection:   Done by JDBC's prepared statements, and clojure.jdbc's use
of them
2. XSS injection:   Depends on templating.  Hiccup requires explicit `(h
..)` calls.  laser is escape by default.  I am unsure about enlive,
clabango, or others.
3. Authentication  Session Management:  I've used friend for
authentication, and bcrypt for encryption.  lib-noir has some functions
that use bcrypt, but I've not used it. Session management can be specified
by the :store given to wrap-session, and defaults to a in memory store.  A
cookie store also exists that provides some protection against cookie
mutation.  Immutant provides a store that can work across a cluster.
4. Insecure Reference:  There is not a standard ORM or similar, so handling
only the correct parameters is up to you.
5. CSRF:  ring-anti-forgery provides a way to add CSRF prevention tokens
6. Security Misconfiguration: This seems to be the domain of chef, pallet,
puppet, capistrano or another deployment tool.  I'm not sure I want my
libraries to mess with deployments.
7. Insecure Cryptographic Storage: Use bcrypt. See 3.
8. Failure to Restrict URL access: I've used friend for authorization.
9. Insufficient Transport Layer Protection: I'd recommend letting your
front end server handle this and redirect to https.  I believe lib-noir has
a middleware that will redirect from http to https if needed. Consider
passing `:secure true` to `wrap-cookies` if you have an https only site.
10. Unvalidated Redirects and Forwards: Url generation is a weakspot in a
compojure based setup. For comparison, pedestal-service wrote its own
routing dsl and stores the routes in a way that allows url generation based
on the context passed in.

I believe the use of many small libraries is what causes the lack of a
single spot for this documentation. I've picked up most of what I described
above by knowing the authors / what to google / asking + watching irc.
 That does seem like an unfortunate situation for anyone new to have to
learn.

-
Nelson Morris

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.