Groovy/Java Integration N Language Elements N Operators

Total Page:16

File Type:pdf, Size:1020Kb

Groovy/Java Integration N Language Elements N Operators #15 CONTENTS INCLUDE: n Groovy/Java Integration n Language Elements n Operators n Groovy Collective Datatypes n Meta Programming n Hot Tips and more... By Dierk König Visit refcardz.com GroovyShell ABOUT GROOVY Use groovy.util.GroovyShell for more flexibility in the Binding and optional pre-parsing: Groovy is a dynamic language for the Java™ Virtual Machine (JVM). It shines with full object-orientation, scriptability, optional GroovyShell shell= new GroovyShell(); typing, operator customization, lexical declarations for the Script scpt = shell.parse("y = x*x"); most common data types, advanced concepts like closures and Binding binding = new Binding(); ranges, compact property syntax and seamless Java™ integra- scpt.setBinding(binding); tion. This reference card provides exactly the kind of information binding.setVariable("x", 2); you are likely to look up when programming Groovy. scpt.run(); (int) binding.getVariable("y"); STARTING GROOVY Chapter 11 of Groovy in Action has more details about Install Groovy from http://groovy.codehaus.org and you will integration options. Here is an overview: have the following commands available: Integration option Features/properties Command Purpose Eval/GroovyShell for small expressions + reloading, security groovy Execute Groovy code GroovyScriptEngine for dependent scripts + reloading groovyc Compile Groovy code - classes, security groovysh Open Groovy shell GroovyClassLoader the catch-all solution + reloading, security groovyConsole Open Groovy UI console Spring Beans integrates with Spring + reloading java2groovy Migration helper JSR-223 easy language switch but limited in API - reloading, security requires Java 6 The groovy command comes with -h and --help options to show all options and required arguments. Typical usages are: www.dzone.com Get More Refcardz! Execute file MyScript.groovy LANGUAGE ELEMENTS groovy MyScript Evaluate (e) on the command line Classes & Scripts groovy -e "print 12.5*Math.PI" A Groovy class declaration looks like in Java. Default visibility modifier is public Print (p) for each line of input echo 12.5 | groovy -pe class MyClass { "line.toDouble() * Math.PI" void myMethod(String argument) { Inline edit (i) filedata.txt by reversing each line and save a backup } groovy -i.bak –pe } → "line.reverse()" data.txt GROOVY/JAVA INTEGRATION Get More Refcardz (They’re free!) From Groovy, you can call any Java code like you would do from Java. It’s identical. n Authoritative content n Designed for developers From Java, you can call Groovy code in the following ways. n Written by top experts Note that you need to have the groovy-all.jar in your classpath. n Latest tools & technologies Cross-compilation n Hot tips & examples Use groovyc, the <groovyc/> ant task or your IDE integration to n compile your groovy code together with your Java code. This Bonus content online enables you to use your Groovy code as if it was written in Java. n New issue every 1-2 weeks Eval Subscribe Now for FREE! Use class groovy.util.Eval for evaluating simple code that is Refcardz.com captured in a Java String: (int) Eval.xyz(1,2,3,"x+y+z"); Groovy DZone, Inc. | www.dzone.com 2 Groovy tech facts at your fingertips Language Elements (Classes and Scripts), continued Customizable Operators, continued When a .groovy file or any other source of Groovy code Operator Method contains code that is not enclosed in a class declaration, a-- a.previous() --a then this code is considered a Script, e.g. a**b a.power(b) println "Hello World" a|b a.or(b) Scripts differ from classes in that they have a Binding that a&b a.and(b) serves as a container for undeclared references (that are not a^b a.xor(b) allowed in classes). ~a ~a a.bitwiseNegate() // sometimes referred to as negate | +a a.positive() // sometimes referred to as unaryMinus | -a a.negative() // sometimes referred to as unaryPlus println text // expected in Binding a[b] a.getAt(b) result = 1 // is put into Binding a[b] = c a.putAt(b, c) Optional Typing a << b a.leftShift(b) Static types can be used like in Java and will be obeyed a >> b a.rightShift(b) at runtime. Dynamic typing is used by replacing the type a >>> b a.rightShiftUnsigned(b) declaration with the def keyword. Formal parameters to switch(a){ b.isCase(a) case b: // b is a classifier method and closure declarations can even omit the def. } [a].grep(b) Properties if(a in b) Properties are declared as fields with the default visibility a == b a.equals(b) modifier, no matter what type is used. a != b ! a.equals(b) a <=> b a.compareTo(b) class MyClass { a > b a.compareTo(b) > 0 String stringProp def dynamicProp a >= b a.compareTo(b) >= 0 } a < b a.compareTo(b) < 0 a <= b a.compareTo(b) <= 0 Java-style getters and setters are compiled into the bytecode a as B a.asType(B) automatically. Properties are referred to like Actively look for opportunities to implement println obj.stringProp // getter Hot operator methods in your own Groovy class. obj.dynamicProp = 1 // setter Tip This often leads to more expressive code. regardless of whether obj was written in Java or Groovy, the Typical candidates are ==, <=>, +, -, <<, respective getters/setters will be called. and isCase(). See also Ranges. Multimethods Methods are dispatched by the runtime type, allowing code like Special Operators class Pers { Operator Meaning Name String name a ? b : c if (a) b else c ternary if boolean equals(Pers other) { a ?: b a ? a : b Elvis name == other.name a?.b a==null ? a : a.b null safe } a(*list) a(list[0], list[1], ...) spread } assert new Pers(name:'x') == new Pers(name:'x') list*.a() [list[0].a(), list[1].a() ...] spread-dot assert new Pers(name:'x') != 1 a.&b reference to method b in method closure object a as closure a.@field direct field access dot-at OPERATORS SIMPLE DATATYPES Customizable Operators Operators can be customized by implementing/ overriding Numbers the respective method. All Groovy numbers are objects, not primitive types. Literal declarations are: Operator Method a + b a.plus(b) Type Example literals a – b a.minus(b) java.lang.Integer 15, 0x1234ffff a * b a.multiply(b) java.lang.Long 100L, 100l java.lang.Float 1.23f, 4.56F a / b a.div(b) java.lang.Double 1.23d, 4.56D a % b a.mod(b) java.math.BigInteger 123g, 456G a++ a.next() ++a java.math.BigDecimal 1.23, 4.56, 1.4E4, 2.8e4, 1.23g, 1.23G DZone, Inc. | www.dzone.com 3 Groovy tech facts at your fingertips Simple Datatypes (Numbers), continued Regular Expressions, continued Coercion rules for math operations are explained in Groovy Symbol Meaning in Action, chapter 3. Some examples to remember are: . any character ^ start of line (or start of document, when in single-line mode) Expression Result type $ end of line (or end of document, when in single-line mode) 1f * 2f Double \d digit character 1f / 2f Double \D any character except digits (Byte)1 + (Byte)2 Integer \s whitespace character 1 * 2L Long \S any character except whitespace 1 / 2 BigDecimal (0.5) \w word character (int)(1/2) Integer (0) \W any character except word characters 1.intdiv(2) Integer (0) \b word boundary Integer.MAX_VALUE+1 Integer () grouping 2**31 Integer (x|y) x or y as in (Groovy|Java|Ruby) 2**33 Long \1 backmatch to group one, e.g. find doubled characters with (.)\1 2**3.5 Double x* zero or more occurrences of x. 2G + 1G BigInteger x+ one or more occurrences of x. 2.5G + 1G BigDecimal x? zero or one occurrence of x. 1.5G == 1.5F Boolean (true) x{m,n} at least “m” and at most “n” occurrences of x. 1.1G == 1.1F Boolean (false) x{m} exactly “m” occurrences of x. [a-f] character class containing the characters 'a', 'b', 'c', 'd', 'e', 'f' Strings [^a] character class containing any character except 'a' 'literal String' (?is:x) switches mode when evaluating x; i turns on ignoreCase, s single-line mode '''literal (?=regex) positive lookahead multiline String''' (?<=text) positive lookbehind def lang = 'Groovy' "GString for $lang" "$lang has ${lang.size()} chars" COLLECTIVE DATATYPES """multiline GString with Ranges late eval at ${-> new Date()}""" Ranges appear inclusively like 0..10 or half-exclusively like Placeholders in GStrings are dereferenced at declaration time 0..<10. They are often enclosed in parentheses since the but their text representation is queried at GString String range operator has low precedence. conversion time. assert (0..10).contains(5) /String with unescaped \ included/ assert (0.0..10.0).containsWithinBounds(3.5) Regular Expressions for (item in 0..10) { println item } for (item in 10..0) { println item } The regex find operator =~ (0..<10).each { println it } The regex match operator ==~ Integer ranges are often used for selecting sublists. Range The regex Pattern operator ~String boundaries can be of any type that definesprevious() , next() and Examples: implements Comparable. Notable examples are String and Date. def twister = 'she sells sea shells' // contains word 'she' Lists assert twister =~ 'she' Lists look like arrays but are of type java.util.List plus new methods. // starts with 'she' and ends with 'shells' [1,2,3,4] == (1..4) assert twister ==~ /she.*shells/ [1,2,3] + [1] == [1,2,3,1] // same precompiled [1,2,3] << 1 == [1,2,3,1] def pattern = ~/she.*shells/ [1,2,3,1] - [1] == [2,3] assert pattern.matcher(twister).matches() [1,2,3] * 2 == [1,2,3,1,2,3] [1,[2,3]].flatten() == [1,2,3] // matches are iterable [1,2,3].reverse() == [3,2,1] // words that start with 'sh' [1,2,3].disjoint([4,5,6]) == true def shwords = (twister =~ /\bsh\w*/).collect{it}.join(' ') [1,2,3].intersect([4,3,1]) == [3,1] assert shwords == 'she shells' [1,2,3].collect{ it+3 } == [4,5,6] [1,2,3,1].unique().size() == 3 // replace through logic [1,2,3,1].count(1) == 2 assert twister.replaceAll(/\w+/){ [1,2,3,4].min() == 1 it.size() [1,2,3,4].max() == 4 } == '3 5 3 6' [1,2,3,4].sum() == 10 [4,2,1,3].sort() == [1,2,3,4] // regex groups to closure params [4,2,1,3].findAll{it%2 == 0} == [4,2] // find words with same start and end def anims=['cat','kangaroo','koala'] def matcher = (twister =~ /(\w)(\w+)\1/) anims[2] == 'koala' matcher.each { full, first, rest -> def kanims = anims[1..2] assert full in ['sells','shells'] anims.findAll{it =~ /k.*/} ==kanims assert first == 's' anims.find{ it =~ /k.*/} ==kanims[0] } anims.grep(~/k.*/) ==kanims → DZone, Inc.
Recommended publications
  • Operator Overloading ______
    Chapter 10: Operator Overloading _________________________________________________________________________________________________________ Consider the following C++ code snippet: vector<string> myVector(kNumStrings); for(vector<string>::iterator itr = myVector.begin(); itr != myVector.end(); ++itr) *itr += "Now longer!"; Here, we create a vector<string> of a certain size, then iterate over it concatenating “Now longer!” to each of the strings. Code like this is ubiquitous in C++, and initially does not appear all that exciting. However, let's take a closer look at how this code is structured. First, let's look at exactly what operations we're performing on the iterator: vector<string> myVector(kNumStrings); for(vector<string>::iterator itr = myVector.begin(); itr != myVector.end(); ++itr) *itr += "Now longer!"; In this simple piece of code, we're comparing the iterator against myVector.end() using the != operator, incrementing the iterator with the ++ operator, and dereferencing the iterator with the * operator. At a high level, this doesn't seem all that out of the ordinary, since STL iterators are designed to look like regular pointers and these operators are all well-defined on pointers. But the key thing to notice is that STL iterators aren't pointers, they're objects, and !=, *, and ++ aren't normally defined on objects. We can't write code like ++myVector or *myMap = 137, so why can these operations be applied to vector<string>::iterator? Similarly, notice how we're concatenating the string “Now longer!” onto the end of the string: vector<string> myVector(kNumStrings); for(vector<string>::iterator itr = myVector.begin(); itr != myVector.end(); ++itr) *itr += "Now longer!"; Despite the fact that string is an object, somehow C++ “knows” what it means to apply += to strings.
    [Show full text]
  • Property Mapping: a Simple Technique for Mobile Robot Programming
    Property Mapping: a simple technique for mobile robot programming Illah R. Nourbakhsh The Robotics Institute, Carnegie Mellon University Pittsburgh, PA 15213 [email protected] Abstract In this paper we present robot observability as a The mobile robot programming problem is a software predictor for diagnostic transparency. Then, we present a engineering challenge that is not easily conquered using language-independent technique called property mapping contemporary software engineering best practices. We for constructing robot programs that are diagnostically propose robot observability as a measure of the diagnostic transparent and thereby achieve high degrees of transparency of a situated robot program, then describe reliability. property mapping as a simple, language-independent approach to implementing reliable robot programs by maximizing robot observability. Examples from real- The Robot Programming Problem world, working robots are given in Lisp and Java. A mobile robot is a situated automata, or a module that comprises one part of a closed system together with the Introduction environment. Fig. 1 shows the standard depiction of a robot, with its outputs labeled as actions and the outputs The recent availability of inexpensive, reliable robot of the environment in turn labeled as percepts. chassis (e.g. ActivMedia Pioneer, IS-Robotics Magellan, Nomad Scout) has broadened the accessibility of mobile robotics research. Because these robots consist of fixed E hardware out-of-the-box, this technology is shifting the actions A P percepts emphasis of mobile robot research from a joint hardware and software design process toward hardware-unaware R mobile robot programming. This is a software design problem, and yet software Figure 1: The standard view of an embedded robot engineering best practices are not very helpful.
    [Show full text]
  • C++ Properties -- a Library Solution
    Document Number: SC22/WG21/N1615=04-0055 Date: 2004-04-09 Author: Lois Goldthwaite Email: [email protected] C++ Properties -- a Library Solution N1600 is a summary of the "property" language extension that is proposed for C++/CLI. I can't help feeling that this is an effort to impose an alien idiom on C++. There is too much of "the compiler will perform black magic behind your back" in it. There are too many ways in which the programmer must be aware that some [pseudo-]data members must be handled in different ways from [real] data members. The C++/CLI draft spec (N1608)says in 8.8.4 and 18.4 that "A property is a member that behaves as if it were a field." I think "behaves" is absolutely the wrong word to use here. A property is behavior that pretends to be state. From an OO design point of view, I think this is A Bad Idea. Behaviour should be visible; state should not. Further on, the document continues, "the X and Y properties can be read and written as though they were fields. In the example above, the properties are used to implement data hiding within the class itself." The subtle advantage of "hiding" a private data member by treating it as a public data member escapes me. Properties are just syntactic saccharine for getter and setter member functions for individual fields. C++ experts have spent years trying to educate people NOT to use public data, to use member functions instead, and now we propose to introduce something that looks just like public data? Do we really want to try to teach people that public fields are still bad, but properties are good, even though they look just the same from outside the class? Moreover, these public fields have side effects! There is a danger that too many novice programmers will prototype their designs using public fields, with the intent of changing them to properties later, if and when it proves necessary, and the general quality of code will suffer because of it.
    [Show full text]
  • Property Conveyances As a Programming Language
    Property Conveyances as a Programming Language Shrutarshi Basu∗ Nate Foster James Grimmelmann Harvard University Cornell University Cornell Law School & Cornell Tech Cambridge, MA, USA Ithaca, NY, USA New York, NY, USA [email protected] [email protected] [email protected] Abstract 1 Introduction Anglo-American law enables property owners to split up Many legal issues depend on vague, open-ended standards. rights among multiple entities by breaking their ownership For example, nuisance law prohibits “unreasonable” interfer- apart into future interests that may evolve over time. The con- ence with neighbors’ use of land. What counts as “unreason- veyances that owners use to transfer and subdivide property able” depends on an eight-factor balancing test, and many of rights follow rigid syntactic conventions and are governed the individual factors are themselves vague and open-ended, by an intricate body of interlocking doctrines that determine including “the social value that the law attaches to the pri- their legal eect. These doctrines have been codied, but mary purpose of the conduct;” and “the suitability of the only in informal and potentially ambiguous ways. particular use or enjoyment invaded to the character of the This paper presents preliminary work in developing a locality.” [American Law Institute 1979] A lawyer who wants formal model for expressing and analyzing property con- to know whether a client’s cement plant will be considered veyances. We develop a domain-specic language capable a nuisance will have to research numerous previous cases, of expressing a wide range of conveyances in a syntax ap- gather extensive facts about the plant and its neighbors, and proximating natural language.
    [Show full text]
  • Dealing with Properties
    Dealing with Properties Martin Fowler [email protected] lmost every object you create needs properties: some statement about the object. A person may have a height, a company may have a CEO, a flight may have a flight Anumber. There are a number of ways to model properties. In this article I will explore some of these ways and when you may want to use them. I’ve often seen patterns touch on this subject, but they usually only cover part of the picture. Here I want to cover the issue more broadly to give a better discussion of the options. The most common, and the simplest case is to use a Fixed Property, that is just declare the attribute on the class. In the vast majority of cases that is all you need to do. Fixed properties begin to fail when you have a large amount of them, or you need to change them frequently, possibly at run time. These forces lead you to the varieties of Dynamic Property. All dynamic properties have the quality of a parameterized attribute where to query a property you need to use a query method with a parameter. The simplest of these is the Flexible Dynamic Property where the parameter is just a string. This makes it easy to define and use properties, but is difficult to control. If you need that control you can use a Defined Dynamic Property where your parameters must be instances of some class. A further step of control allows you to strongly type your dynamic property with a Typed Dynamic Property.
    [Show full text]
  • Alice Glossary
    Adventures in Alice Programming // Glossary of Useful Terms by Michael Marion // July 2012 Worlds, methods, functions, properties, variables - it’s pretty easy to get all of the terminology and concept matter confused when it comes to programming in Alice. To that point, we’ve developed this handy reference to use. Hopefully it helps you not to get mixed up. Enjoy! World A world in Alice encompasses everything. Just as we’d say that everyone and everything exists in our world in real life; every object, method, event, or anything else lies inside the world in Alice. The whole .a2w file represents the world. Object An object is just what it sounds like. Any sort of three-dimensional shape such as a person, animal, piece of furniture, building, or anything else of the sort in your world is an object. Most objects are added to the world via the Add Objects button, but some - the ground, camera, and light, for instance - are there by default. There are also two-dimensional objects such as text and billboards. Properties An object’s properties are also what they sound like. All objects have certain properties - whether or not they’re showing, their color, their position, and so forth. Color Defines the color of an object. There is a limited number of color choices in Alice, but it covers all primary colors and some extras, including red, blue, green, yellow, black, and cyan. To specify a white object, select “no color”. Opacity Defines the transparency of an object. Unlike isShowing, setting the opacity to a middle amount allows it to be only slightly transparent.
    [Show full text]
  • Operator Overloading in C Sharp with Simple Example
    Operator Overloading In C Sharp With Simple Example Clonic and thick-witted Stephan synopsize his lashkars violated commence laughably. Selig cosponsors his self-understanding refurbishes incompletely, but oculomotor Elias never supernaturalise so earthwards. Morning Robbie never spatted so ineptly or infract any instance detractingly. We will send you exclusive offers when we launch our new service. Even an instance of a class cannot access its private members. Overloading also has surprising ramifications. Net mvc with plus method overloading example overloads must have a simple examples and conceptual way they occur at times. The example with encapsulation comes in. Get in with implicit cast operator methods and examples of overloaded only overload resolution and commentary before. If a variety of ansi sql, if many various other. The example with it in a directional vector class methods in operations of examples of parameters, we avoid building reactive concurrent applications. It adds numbers, concatenates strings or delegates; indicates the sign of a number. In her sense, MATLAB can be used to rapidly prototype an algorithm. Operator specifies an object or two shift operator overloading and b are compiled for this website is only not change these arguments should be accessed from? The process four sections each implement one of different concrete classes. Calling a simple examples of creating an underscore followed if we can be completely new scheduling demands and meaningful. You can definitely overload Casting. This operator with operators, simple examples illustrate, most ad packages based off of operations. We offer such diverse selection of courses from leading universities and cultural institutions from around in world.
    [Show full text]
  • Oberon Script: a Lightweight Compiler and Runtime System for the Web
    Oberon Script: A Lightweight Compiler and Runtime System for the Web Ralph Sommerer1 1 Microsoft Research, 7 J J Thomson Avenue, Cambridge, United Kingdom [email protected] Abstract. Oberon Script is a scripting language and runtime system for build- ing interactive Web Client applications. It is based on the Oberon programming language and consists of a compiler that translates Oberon Script at load-time into JavaScript code, and a small runtime system that detects and compiles script sections written in Oberon Script. 1 Introduction Oberon is the name of a modular, extensible operating system for single user worksta- tions [19], and also of an object-oriented programming language specifically devel- oped to implement the former [17]. Although originally designed as the native operat- ing system for custom built workstations, Oberon was subsequently ported to various different computing platforms including personal computers [2][4] and Unix worksta- tions [1][14][15]. With the recent emergence and proliferation of sophisticated Web client applica- tions, the Web browser has become a computing platform on its own. It offers the Web application programmer scripting facilities to programmatically interact with a Web server, and to manipulate the Web page in-place and without reloading. It thus allows the construction of complex Web application user interfaces that are not lim- ited to the page-based hypertext model anymore. As the Web browser morphs into a runtime system and operating platform for Web client application, the question arises whether it can provide a suitable target platform for one more installment of Oberon, especially in light of all previous porting efforts that have shown Oberon’s demands of the host platform to be very limited.
    [Show full text]
  • Project Oberon the Design of an Operating System and Compiler
    1 Niklaus Wirth Jürg Gutknecht Project Oberon The Design of an Operating System and Compiler Edition 2005 2 Project Oberon Preface This book presents the results of Project Oberon, namely an entire software environment for a modern workstation. The project was undertaken by the authors in the years 1986-89, and its primary goal was to design and implement an entire system from scratch, and to structure it in such a way that it can be described, explained, and understood as a whole. In order to become confronted with all aspects, problems, design decisions and details, the authors not only conceived but also programmed the entire system described in this book, and more. Although there exist numerous books explaining principles and structures of operating systems, there is a lack of descriptions of systems actually implemented and used. We wished not only to give advice on how a system might be built, but to demonstrate how one was built. Program listings therefore play a key role in this text, because they alone contain the ultimate explanations. The choice of a suitable formalism therefore assumed great importance, and we designed the language Oberon as not only an effective vehicle for implementation, but also as a publication medium for algorithms in the spirit in which Algol 60 had been created three decades ago. Because of its structure, the language Oberon is equally well suited to exhibit global, modular structures of programmed systems. In spite of the small number of man-years spent on realizing the Oberon System, and in spite of its compactness letting its description fit a single book, it is not an academic toy, but rather a versatile workstation system that has found many satisfied and even enthusiastic users in academia and industry.
    [Show full text]
  • Object-Oriented Programming in Oberon-2
    Hanspeter Mössenböck Object-Oriented Programming in Oberon-2 Second Edition © Springer‐Verlag Berlin Heidelberg 1993, 1994 This book is out of print and is made available as PDF with the friendly permission of Springer‐Verlag Contents 1 Overview......................................................................................... 1 1.1 Procedure-Oriented Thinking............................................. 1 1.2 Object-Oriented Thinking .................................................... 2 1.3 Object-Oriented Languages................................................. 3 1.4 How OOP Differs from Conventional Programming...... 6 1.5 Classes as Abstraction Mechanisms ................................... 9 1.6 History of Object-Oriented Languages ............................ 11 1.7 Summary .............................................................................. 12 2 Oberon-2........................................................................................ 13 2.1 Features of Oberon-2 .......................................................... 14 2.2 Declarations ......................................................................... 14 2.3 Expressions .......................................................................... 16 2.4 Statements ............................................................................ 18 2.5 Procedures............................................................................ 19 2.6 Modules................................................................................ 21 2.7 Commands..........................................................................
    [Show full text]
  • Discovering Hidden Properties to Attack Node.Js Ecosystem
    Discovering Hidden Properties to Attack Node.js Ecosystem Feng Xiao, Jianwei Huang, Yichang Xiong, Guangliang Yang, Hong Hu, Guofei Gu, Wenke Lee #BHUSA @BLACKHATEVENTS Feng Xiao @f3ixiao • CS PhD student at Georgia Tech. • Vulnerability researcher. Develop tools to detect and exploit 0days. • Focus on web/application security, but also enjoy network security+ and virtualization security. +Hacking the Brain: Customize Evil Protocol to Pwn an SDN Controller. DEF CON 2018 #BHUSA @BLACKHATEVENTS Agenda • Hi, you’ve found some new Node.js vulnerabilities! what are they? • Sounds interesting, you’ve built bug finding tools? how does it work? • Cool. More details on the real-world impact? #BHUSA @BLACKHATEVENTS $ cat vuls.txt #BHUSA @BLACKHATEVENTS Background $ man node • A JavaScript runtime built on Chrome’s v8 engine. Apps AppApps Code Core Modules libuv … Node.js Operating System #BHUSA @BLACKHATEVENTS $ man node • A JavaScript runtime built on Chrome’s v8 engine. • Widely-used for deploying server-side programs and desktop apps. #BHUSA @BLACKHATEVENTS $ man node • A JavaScript runtime built on Chrome’s v8 engine. • Widely-used for deploying server-side programs and desktop apps. • Object sharing is a very popular communication method for Node.js web apps. Request parsing modules that convert input into objects. #BHUSA @BLACKHATEVENTS Object Sharing GET /update?age=23 Querystring-based Serialization Client-side JS {func: update, age: 23} JSON-based Serialization Node.js web #BHUSA @BLACKHATEVENTS What if we inject additional properties that are unexpected to the program? Hidden Property Abusing HPA leverages the widely-used data exchanging feature in Node.js (object sharing) to tamper or forge critical program states of Node.js applications.
    [Show full text]
  • A GROOVY Way to Enhance Your SAS Life
    Paper CT05 A GROOVY way to enhance your SAS life Karl Kennedy, GCE Solutions, Manchester, UK ABSTRACT PROC GROOVY is a relatively new (SAS® 9.3+) and little-known SAS procedure that can unleash the power of Apache's GROOVY language (Java™-syntax compatible object-oriented programming language) within your SAS environment. To display the power of PROC GROOVY two methods for producing a bookmarked PDF containing trial results (tables, figures, and listings) are described. The first method uses PROC GROOVY/Java while the second uses standard BASE SAS. The primary goal of this paper is to show that with minimal Java and PROC GROOVY knowledge the programming burden/complexity of the task can be greatly reduced, for example by removing the requirement to parse an RTF file. This is achieved by utilising Java's vast collection of Application Programming Interfaces (APIs). A secondary goal is to open the world of Java to SAS programmers. INTRODUCTION In Clinical Trial reporting it is often required to provide the analysis results (tables, figures, and listings (TFLs)) in one complete PDF document. In a previous role, a client made such a request at the end of the study and without any process in place to handle this request we had to investigate how to combine all the RTFs into one PDF document. Fortunately, an excellent paper “A SAS Macro Utility to Append SAS-Generated RTF Outputs and Create the Table of Contents” [1] describes how to append RTF tables and listings into one RTF document which could then be saved as a PDF file.
    [Show full text]