Google Cloud
This example below demonstrates how to communicate with the Google Cloud Platform:
Tip
Needed Nugets: GHIElectronics.TinyCLR.Networking.Mqtt
static void DoTestGoogleCloudMqtt()
{
string iotHubName = "mqtt.googleapis.com";
int iotPort = 8883;
var projectId = "your project id";
var cloudRegion = "your region";
var registryId = "your register id";
var deviceId = "your device id";
var clientId = $"projects/{projectId}" +
$"/locations/{cloudRegion}" +
$"/registries/{registryId}" +
$"/devices/{deviceId}";
var message = "My message";
var caCertSource = UTF8Encoding.UTF8.GetBytes("Your CA certificate");
var clientCertSource = UTF8Encoding.UTF8.GetBytes("Your Client certificate");
X509Certificate CaCert = new X509Certificate(caCertSource);
X509Certificate ClientCert = new X509Certificate(clientCertSource);
var clientSetting = new MqttClientSetting
{
BrokerName = iotHubName,
BrokerPort = iotPort,
CaCertificate = CaCert,
ClientCertificate = null,
SslProtocol = System.Security.Authentication.SslProtocols.Tls12
};
var iotClient = new Mqtt(clientSetting);
var jwt = "your jwt";
iotClient.PublishReceivedChanged += (a, b) =>
{ Debug.WriteLine("Publish Received Changed."); };
iotClient.PublishedChanged += (a, b, c) => { Debug.WriteLine("Published Changed."); }; ;
iotClient.SubscribedChanged += (a, b) => { Debug.WriteLine("Subscribed Changed."); };
iotClient.ConnectedChanged += (a) => { Debug.WriteLine("Connected Changed."); };
iotClient.UnsubscribedChanged += (a, b) => { Debug.WriteLine("Unsubscribed Changed."); };
var connectSetting = new MqttConnectionSetting
{
ClientId = clientId,
UserName = "unused",
Password = jwt
};
string topic = $"/devices/{deviceId}/events";
var returnCode = iotClient.Connect(connectSetting);
if (returnCode == ConnectReturnCode.ConnectionAccepted)
{
iotClient.Publish(topic
, UTF8Encoding.UTF8.GetBytes(message)
, QoSLevel.LeastOnce
, false, 1);
}
}
This example requires projectId, cloudRegion, registryId, and deviceId, which will be available when you register a Google Cloud account.
a client certificate and private key are also provided when you register your account.
You may want to visit https://cloud.google.com/iot/docs/quickstart for more detail.
JWT
When connect to google cloud, you also need a JWT (JSON Web Token) to be used as password if using MQTT.
For an easy way to generate a JWT visit https://jwt.io/. However, if you are concerned about sharing your private key with a third party site, there are a multitude of other options.
Warning
By using https://jwt.io/, your private key is shared with a third party. This should be used only for testing purpose."
There are also two fields iat
(issue at), and exp
(expire), they contains time in Unix Timestamp format. You can convert them online at https://www.epochconverter.com/
Note
The google cloud connection accepts a maximum expire time of 24 hours, meaning the timespan between iat
and exp
must be less that 24 hours.


This is it! Episode 1!
Great mate Murphy McLachlan host of Beer Eye With Your Mates Guys joins Simon this week to discuss creating a bar for dogs.
Can dogs drink alcohol? Let’s find out!
This is it! Episode 1!
Great mate Murphy McLachlan host of Beer Eye With Your Mates Guys joins Simon this week to discuss creating a bar for dogs.
Can dogs drink alcohol? Let’s find out!
So excited about the podcast that we’re launching a week early!
The first 3 Eps will all drop now this Monday the 8th of August!
Or using the following URL: http://letsmakebillions.libsyn.com/rss
Hey everyone! There’s a short intro for the show up now on iTunes
Just gives some basic info on the show but the best bit is you can now subscribe!
Listen here or on iTunes
Or using the following URL: http://letsmakebillions.libsyn.com/rss
Let’s Make Billions is now up in the iTunes store!
If iTunes isn’t your thing then the url is: http://letsmakebillions.libsyn.com/rss
Just add that to whatever you listen to podcasts through and all will be good!
Have added a little intro to the podcast for now but the first 3 Episodes will drop August 15th! Woohoo!
Subscribe now and get it in your little ear holes!
This is it!
Launch date is set.

But for now follow us on social media:


Before Change
normalized_sample = rht.normalize_sample(X)
normalized_pred = self.predict(normalized_sample)
_, n_features = get_dimensions(X)
_, n_targets = get_dimensions(y)
normalized_target_value = rht.normalized_target_value(y)
After Change
normalized_target_value = rht.normalized_target_value(y)
self.perceptron_weight += learning_ratio * \
(normalized_target_value - normalized_pred)[:, None] @ \
normalized_sample[None, :]
self.normalize_perceptron_weights()
def normalize_perceptron_weights(self):


Shigeru Chiba
Javassist is a class library for dealing with Java bytecode.
Java bytecode is stored in a binary file called a class file.
Each class file contains one Java class or interface.
The class This program first obtains a From the implementation viewpoint, The You can directly load the To define a new class from scratch, This program defines a class If a A frozen After If To disallow pruning a particular The The default
This statement registers the class path that was used for loading
the class of the object that
You can register a directory name as the class search path.
For example, the following code adds a directory
The search path that the users can add is not only a directory but also
a URL:
This program adds "http://www.javassist.org:80/java/" to the class search
path. This URL is used only for searching classes belonging to a
package Furthermore, you can directly give a byte array
to a The obtained If you do not know the fully-qualified name of the class, then you
can use The users can extend the class search path. They can define a new
class implementing
A
For example, suppose that a new method
This specification of You must not call any method on that
Another idea is to occasionally replace a This creates a Note that
If a program is running on a web application server,
creating multiple instances of
Multiple
If
If A new class can be defined as a copy of an existing class.
The program below does that:
This program first obtains the Note that Therefore, if The To create another copy of the default instance of
If you have two Once a To avoid this restriction, you should call If If what classes must be modified is known in advance,
the easiest way for modifying the classes is as follows:
If whether a class is modified or not is determined at load time,
the users must make Javassist collaborate with a class loader.
Javassist can be used with a class loader so that bytecode can be
modified at load time. The users of Javassist can define their own
version of class loader but they can also use a class loader provided
by Javassist.
The The following program shows how to use Note that the program above depends on the fact that the
then the original If the program is running on some application server such as
JBoss and Tomcat, the context class loader used by
would work. You should give In Java, multiple class loaders can coexist and
each class loader creates its own name space.
Different class loaders can load different class files with the
same class name. The loaded two classes are regarded as different
ones. This feature enables us to run multiple application programs
on a single JVM even if these programs include different classes
with the same name.
If the same class file is loaded by two distinct class loaders,
the JVM makes two distinct classes with the same name and definition.
The two classes are regarded as different ones.
Since the two classes are not identical, an instance of one class is
not assignable to a variable of the other class. The cast operation
between the two classes fails
and throws a For example, the following code snippet throws an exception:
The Multiple class loaders form a tree structure.
Each class loader except the bootstrap loader has a
parent class loader, which has normally loaded the class of that child
class loader. Since the request to load a class can be delegated along this
hierarchy of class loaders, a class may be loaded by a class loader that
you do not request the class loading.
Therefore, the class loader that has been requested to load a class C
may be different from the loader that actually loads the class C.
For distinction, we call the former loader the initiator of C
and we call the latter loader the real loader of C.
Furthermore, if a class loader CL requested to load a class C
(the initiator of C) delegates
to the parent class loader PL, then the class loader CL is never requested
to load any classes referred to in the definition of the class C.
CL is not the initiator of those classes.
Instead, the parent class loader PL becomes their initiators
and it is requested to load them.
The classes that the definition of a class C referes to are loaded by
the real loader of C.
To understand this behavior, let's consider the following example.
Suppose that a class Next, let's consider a slightly modified example.
Now, the definition of
If L does not delegate to PL when This behavior is somewhat inconvenient but necessary.
If the following statement:
did not throw an exception,
then the programmer of
For more details of class loaders in Java, the following paper would
be helpful:
Javassist provides a class loader
For example, This program modifies a class If the users want to modify a class on demand when it is loaded,
the users can add an event listener to a The method For example, the following event listener changes all classes
to public classes just before they are loaded.
Note that To run an application class To run this program, do:
The class Note that application classes like This search order allows loading modified classes by Javassist.
However, it delegates to the parent class loader if it fails
to find modified classes for some reason. Once a class is loaded by
the parent class loader, the other classes referred to in that class will be
also loaded by the parent class loader and thus they are never modified.
Recall that all the classes referred to in a class C are loaded by the
real loader of C.
If your program fails to load a modified class, you should
make sure whether all the classes using that class have been loaded by
A simple class loader using Javassist is as follows:
The class The class loader loads the class This is the simplest way of using Javassist. However, if you write
a more complex class loader, you may need detailed knowledge of
Java's class loading mechanism. For example, the program above puts the
The system classes like If your application needs to do that, the system classes must be
statically modified. For example, the following program
adds a new field This program produces a file To run your program Suppose that the definition of If the modified Note: Applications that use this technique for the purpose of
overriding a system class in If the JVM is launched with the JPDA (Java Platform Debugger
Architecture) enabled, a class is dynamically reloadable. After the
JVM loads a class, the old version of the class definition can be
unloaded and a new one can be reloaded again. That is, the definition
of that class can be dynamically modified during runtime. However,
the new class definition must be somewhat compatible to the old one.
The JVM does not allow schema changes between the two versions.
They have the same set of methods and fields.
Javassist provides a convenient class for reloading a class at runtime.
For more information, see the API documentation of
1. Reading and writing bytecode
Javassist.CtClass
is an abstract
representation of a class file. A CtClass
(compile-time
class) object is a handle for dealing with a class file. The
following program is a very simple example:
ClassPool pool = ClassPool.getDefault();
CtClass cc = pool.get("test.Rectangle");
cc.setSuperclass(pool.get("test.Point"));
cc.writeFile();
ClassPool
object, which
controls bytecode modification with Javassist. The
ClassPool
object is a container of CtClass
object representing a class file. It reads a class file on demand for
constructing a CtClass
object and records the
constructed object for responding later accesses.
To modify the definition of a class, the users must first obtain
from a ClassPool
object
a reference to a CtClass
object representing that class.
get()
in ClassPool
is used for this purpose.
In the case of the program shown above, the
CtClass
object representing a class
test.Rectangle
is obtained from the
ClassPool
object and it is assigned to a variable
cc
.
The ClassPool
object returned by getDefault()
searches the default system search path.
ClassPool
is a hash
table of CtClass
objects, which uses the class names as
keys. get()
in ClassPool
searches this hash
table to find a CtClass
object associated with the
specified key. If such a CtClass
object is not found,
get()
reads a class file to construct a new
CtClass
object, which is recorded in the hash table and
then returned as the resulting value of get()
.
CtClass
object obtained from a ClassPool
object can be modified
(details of how to modify
a CtClass
will be presented later).
In the example above, it is modified so that the superclass of
test.Rectangle
is changed into a class
test.Point
. This change is reflected on the original
class file when writeFile()
in CtClass()
is
finally called.
writeFile()
translates the CtClass
object
into a class file and writes it on a local disk.
Javassist also provides a method for directly obtaining the
modified bytecode. To obtain the bytecode, call toBytecode()
:
byte[] b = cc.toBytecode();
CtClass
as well:
Class clazz = cc.toClass();
toClass()
requests the context class loader for the current
thread to load the class file represented by the CtClass
. It
returns a java.lang.Class
object representing the loaded class.
For more details, please see this section below.
Defining a new class
makeClass()
must be called on a ClassPool
.
ClassPool pool = ClassPool.getDefault();
CtClass cc = pool.makeClass("Point");
Point
including no members.
Member methods of Point
can be created with
factory methods declared in CtNewMethod
and
appended to Point
with addMethod()
in CtClass
.
makeClass()
cannot create a new interface;
makeInterface()
in ClassPool
can do.
Member methods in an interface can be created with
abstractMethod()
in CtNewMethod
.
Note that an interface method is an abstract method.
Frozen classes
CtClass
object is converted into a class file by
writeFile()
, toClass()
, or
toBytecode()
, Javassist freezes that CtClass
object. Further modifications of that CtClass
object are
not permitted. This is for warning the developers when they attempt
to modify a class file that has been already loaded since the JVM does
not allow reloading a class.
CtClass
can be defrost so that
modifications of the class definition will be permitted. For example,
CtClasss cc = ...;
:
cc.writeFile();
cc.defrost();
cc.setSuperclass(...); // OK since the class is not frozen.
defrost()
is called, the CtClass
object can be modified again.
ClassPool.doPruning
is set to true
,
then Javassist prunes the data structure contained
in a CtClass
object
when Javassist freezes that object.
To reduce memory
consumption, pruning discards unnecessary attributes
(attribute_info
structures) in that object.
For example, Code_attribute
structures (method bodies)
are discarded.
Thus, after a
CtClass
object is pruned, the bytecode of a method is not
accessible except method names, signatures, and annotations.
The pruned CtClass
object cannot be defrost again.
The default value of ClassPool.doPruning
is false
.
CtClass
,
stopPruning()
must be called on that object in advance:
CtClasss cc = ...;
cc.stopPruning(true);
:
cc.writeFile(); // convert to a class file.
// cc is not pruned.
CtClass
object cc
is not pruned.
Thus it can be defrost after writeFile()
is called.
Note:
While debugging, you might want to temporarily stop pruning and freezing
and write a modified class file to a disk drive.
debugWriteFile()
is a convenient method
for that purpose. It stops pruning, writes a class file, defrosts it,
and turns pruning on again (if it was initially on).
Class search path
ClassPool
returned
by a static method ClassPool.getDefault()
searches the same path that the underlying JVM (Java virtual machine) has.
If a program is running on a web application server such as JBoss and Tomcat,
the ClassPool
object may not be able to find user classes
since such a web application server uses multiple class loaders as well as
the system class loader. In that case, an additional class path must be
registered to the ClassPool
. Suppose that pool
refers to a ClassPool
object:
pool.insertClassPath(new ClassClassPath(this.getClass()));
this
refers to.
You can use any Class
object as an argument instead of
this.getClass()
. The class path used for loading the
class represented by that Class
object is registered.
/usr/local/javalib
to the search path:
ClassPool pool = ClassPool.getDefault();
pool.insertClassPath("/usr/local/javalib");
ClassPool pool = ClassPool.getDefault();
ClassPath cp = new URLClassPath("www.javassist.org", 80, "/java/", "org.javassist.");
pool.insertClassPath(cp);
org.javassist
. For example, to load a class
org.javassist.test.Main
, its class file will be obtained from:
http://www.javassist.org:80/java/org/javassist/test/Main.class
ClassPool
object
and construct a CtClass
object from that array. To do this,
use ByteArrayClassPath
. For example,
ClassPool cp = ClassPool.getDefault();
byte[] b = a byte array;
String name = class name;
cp.insertClassPath(new ByteArrayClassPath(name, b));
CtClass cc = cp.get(name);
CtClass
object represents
a class defined by the class file specified by b
.
The ClassPool
reads a class file from the given
ByteArrayClassPath
if get()
is called
and the class name given to get()
is equal to
one specified by name
.
makeClass()
in ClassPool
:
ClassPool cp = ClassPool.getDefault();
InputStream ins = an input stream for reading a class file;
CtClass cc = cp.makeClass(ins);
makeClass()
returns the CtClass
object
constructed from the given input stream. You can use
makeClass()
for eagerly feeding class files to
the ClassPool
object. This might improve performance
if the search path includes a large jar file. Since
a ClassPool
object reads a class file on demand,
it might repeatedly search the whole jar file for every class file.
makeClass()
can be used for optimizing this search.
The CtClass
constructed by makeClass()
is kept in the ClassPool
object and the class file is never
read again.
ClassPath
interface and give an
instance of that class to insertClassPath()
in
ClassPool
. This allows a non-standard resource to be
included in the search path.
2. ClassPool
ClassPool
object is a container of CtClass
objects. Once a CtClass
object is created, it is
recorded in a ClassPool
for ever. This is because a
compiler may need to access the CtClass
object later when
it compiles source code that refers to the class represented by that
CtClass
.
getter()
is added
to a CtClass
object representing Point
class. Later, the program attempts to compile source code including a
method call to getter()
in Point
and use the
compiled code as the body of a method, which will be added to another
class Line
. If the CtClass
object representing
Point
is lost, the compiler cannot compile the method call
to getter()
. Note that the original class definition does
not include getter()
. Therefore, to correctly compile
such a method call, the ClassPool
must contain all the instances of CtClass
all the time of
program execution.
Avoid out of memory
ClassPool
may cause huge memory
consumption if the number of CtClass
objects becomes
amazingly large (this rarely happens since Javassist tries to reduce
memory consumption in various ways).
To avoid this problem, you
can explicitly remove an unnecessary CtClass
object from
the ClassPool
. If you call detach()
on a
CtClass
object, then that CtClass
object is
removed from the ClassPool
. For example,
CtClass cc = ... ;
cc.writeFile();
cc.detach();
CtClass
object after detach()
is called.
However, you can call get()
on ClassPool
to make a new instance of CtClass
representing
the same class. If you call get()
, the ClassPool
reads a class file again and newly creates a CtClass
object, which is returned by get()
.
ClassPool
with
a new one and discard the old one.
To create a new instance of ClassPool
, execute the following
code snippet:
ClassPool cp = new ClassPool(true);
// if needed, append an extra search path by appendClassPath()
ClassPool
object that behaves as the
default ClassPool
returned by
ClassPool.getDefault()
does.
Note that ClassPool.getDefault()
is a singleton factory method
provided for convenience. It creates a ClassPool
object in
the same way shown above although it keeps a single instance of
ClassPool
and reuses it.
A ClassPool
object returned by getDefault()
does not have a special role. getDefault()
is a convenience
method.
new ClassPool(true)
is a convenient constructor,
which constructs a ClassPool
object and appends the system
search path to it. Calling that constructor is
equivalent to the following code:
ClassPool cp = new ClassPool();
cp.appendSystemPath(); // or append another path by appendClassPath()
Cascaded ClassPools
ClassPool
might be necessary;
an instance of ClassPool
should be created
for each class loader (i.e. container).
The program should create a ClassPool
object by not calling
getDefault()
but a constructor of ClassPool
.
ClassPool
objects can be cascaded like
java.lang.ClassLoader
. For example,
ClassPool parent = ClassPool.getDefault();
ClassPool child = new ClassPool(parent);
child.insertClassPath("./classes");
child.get()
is called, the child ClassPool
first delegates to the parent ClassPool
. If the parent
ClassPool
fails to find a class file, then the child
ClassPool
attempts to find a class file
under the ./classes
directory.
child.childFirstLookup
is true, the child
ClassPool
attempts to find a class file before delegating
to the parent ClassPool
. For example,
ClassPool parent = ClassPool.getDefault();
ClassPool child = new ClassPool(parent);
child.appendSystemPath(); // the same class path as the default one.
child.childFirstLookup = true; // changes the behavior of the child.
Changing a class name for defining a new class
ClassPool pool = ClassPool.getDefault();
CtClass cc = pool.get("Point");
cc.setName("Pair");
CtClass
object for
class Point
. Then it calls setName()
to
give a new name Pair
to that CtClass
object.
After this call, all occurrences of the class name in the class
definition represented by that CtClass
object are changed
from Point
to Pair
. The other part of the
class definition does not change.
setName()
in CtClass
changes a
record in the ClassPool
object. From the implementation
viewpoint, a ClassPool
object is a hash table of
CtClass
objects. setName()
changes
the key associated to the CtClass
object in the hash
table. The key is changed from the original class name to the new
class name.
get("Point")
is later called on the
ClassPool
object again, then it never returns the
CtClass
object that the variable cc
refers to.
The ClassPool
object reads
a class file
Point.class
again and it constructs a new CtClass
object for class Point
.
This is because the CtClass
object associated with the name
Point
does not exist any more.
See the followings:
ClassPool pool = ClassPool.getDefault();
CtClass cc = pool.get("Point");
CtClass cc1 = pool.get("Point"); // cc1 is identical to cc.
cc.setName("Pair");
CtClass cc2 = pool.get("Pair"); // cc2 is identical to cc.
CtClass cc3 = pool.get("Point"); // cc3 is not identical to cc.
cc1
and cc2
refer to the same instance of
CtClass
that cc
does whereas
cc3
does not. Note that, after
cc.setName("Pair")
is executed, the CtClass
object that cc
and cc1
refer to represents
the Pair
class.
ClassPool
object is used to maintain one-to-one
mapping between classes and CtClass
objects. Javassist
never allows two distinct CtClass
objects to represent
the same class unless two independent ClassPool
are created.
This is a significant feature for consistent program
transformation.
ClassPool
, which is returned by
ClassPool.getDefault()
, execute the following code
snippet (this code was already shown above):
ClassPool cp = new ClassPool(true);
ClassPool
objects, then you can
obtain, from each ClassPool
, a distinct
CtClass
object representing the same class file. You can
differently modify these CtClass
objects to generate
different versions of the class.
Renaming a frozen class for defining a new class
CtClass
object is converted into a class file
by writeFile()
or toBytecode()
, Javassist
rejects further modifications of that CtClass
object.
Hence, after the CtClass
object representing Point
class is converted into a class file, you cannot define Pair
class as a copy of Point
since executing setName()
on Point
is rejected.
The following code snippet is wrong:
ClassPool pool = ClassPool.getDefault();
CtClass cc = pool.get("Point");
cc.writeFile();
cc.setName("Pair"); // wrong since writeFile() has been called.
getAndRename()
in ClassPool
. For example,
ClassPool pool = ClassPool.getDefault();
CtClass cc = pool.get("Point");
cc.writeFile();
CtClass cc2 = pool.getAndRename("Point", "Pair");
getAndRename()
is called, the ClassPool
first reads Point.class
for creating a new CtClass
object representing Point
class. However, it renames that
CtClass
object from Point
to Pair
before
it records that CtClass
object in a hash table.
Thus getAndRename()
can be executed after writeFile()
or toBytecode()
is called on the the CtClass
object representing Point
class.
3. Class loader
CtClass
object by calling
ClassPool.get()
,
writeFile()
or toBytecode()
on that CtClass
object to obtain a modified class file.
3.1 The
toClass
method in CtClass
CtClass
provides a convenience method
toClass()
, which requests the context class loader for
the current thread to load the class represented by the CtClass
object. To call this method, the caller must have appropriate permission;
otherwise, a SecurityException
may be thrown.
toClass()
:
public class Hello {
public void say() {
System.out.println("Hello");
}
}
public class Test {
public static void main(String[] args) throws Exception {
ClassPool cp = ClassPool.getDefault();
CtClass cc = cp.get("Hello");
CtMethod m = cc.getDeclaredMethod("say");
m.insertBefore("{ System.out.println(\"Hello.say():\"); }");
Class c = cc.toClass();
Hello h = (Hello)c.newInstance();
h.say();
}
}
Test.main()
inserts a call to println()
in the method body of say()
in Hello
. Then
it constructs an instance of the modified Hello
class
and calls say()
on that instance.
Hello
class is never loaded before toClass()
is invoked. If not, the JVM would load the original
Hello
class before toClass()
requests to
load the modified Hello
class. Hence loading the
modified Hello
class would be failed
(LinkageError
is thrown). For example, if
main()
in Test
is something like this:
public static void main(String[] args) throws Exception {
Hello orig = new Hello();
ClassPool cp = ClassPool.getDefault();
CtClass cc = cp.get("Hello");
:
}
Hello
class is loaded at the first
line of main
and the call to toClass()
throws an exception since the class loader cannot load two different
versions of the Hello
class at the same time.
toClass()
might be inappropriate. In this case, you
would see an unexpected ClassCastException
. To avoid
this exception, you must explicitly give an appropriate class loader
to toClass()
. For example, if bean
is your
session bean object, then the following code:
CtClass cc = ...;
Class c = cc.toClass(bean.getClass().getClassLoader());
toClass()
the class loader
that has loaded your program (in the above example, the class of
the bean
object).
toClass()
is provided for convenience. If you need
more complex functionality, you should write your own class loader.
3.2 Class loading in Java
Note: The JVM does not allow dynamically reloading a class.
Once a class loader loads a class, it cannot reload a modified
version of that class during runtime. Thus, you cannot alter
the definition of a class after the JVM loads it.
However, the JPDA (Java Platform Debugger Architecture) provides
limited ability for reloading a class.
See Section 3.6.
ClassCastException
.
MyClassLoader myLoader = new MyClassLoader();
Class clazz = myLoader.loadClass("Box");
Object obj = clazz.newInstance();
Box b = (Box)obj; // this always throws ClassCastException.
Box
class is loaded by two class loaders.
Suppose that a class loader CL loads a class including this code snippet.
Since this code snippet refers to MyClassLoader
,
Class
, Object
, and Box
,
CL also loads these classes (unless it delegates to another class loader).
Hence the type of the variable b
is the Box
class loaded by CL.
On the other hand, myLoader
also loads the Box
class. The object obj
is an instance of
the Box
class loaded by myLoader
.
Therefore, the last statement always throws a
ClassCastException
since the class of obj
is
a different verison of the Box
class from one used as the
type of the variable b
.
public class Point { // loaded by PL
private int x, y;
public int getX() { return x; }
:
}
public class Box { // the initiator is L but the real loader is PL
private Point upperLeft, size;
public int getBaseX() { return upperLeft.x; }
:
}
public class Window { // loaded by a class loader L
private Box box;
public int getBaseX() { return box.getBaseX(); }
}
Window
is loaded by a class loader L.
Both the initiator and the real loader of Window
are L.
Since the definition of Window
refers to Box
,
the JVM will request L to load Box
.
Here, suppose that L delegates this task to the parent class loader PL.
The initiator of Box
is L but the real loader is PL.
In this case, the initiator of Point
is not L but PL
since it is the same as the real loader of Box
.
Thus L is never requested to load Point
.
public class Point {
private int x, y;
public int getX() { return x; }
:
}
public class Box { // the initiator is L but the real loader is PL
private Point upperLeft, size;
public Point getSize() { return size; }
:
}
public class Window { // loaded by a class loader L
private Box box;
public boolean widthIs(int w) {
Point p = box.getSize();
return w == p.getX();
}
}
Window
also refers to
Point
. In this case, the class loader L must
also delegate to PL if it is requested to load Point
.
You must avoid having two class loaders doubly load the same
class. One of the two loaders must delegate to
the other.
Point
is loaded, widthIs()
would throw a ClassCastException.
Since the real loader of Box
is PL,
Point
referred to in Box
is also loaded by PL.
Therefore, the resulting value of getSize()
is an instance of Point
loaded by PL
whereas the type of the variable p
in widthIs()
is Point
loaded by L.
The JVM regards them as distinct types and thus it throws an exception
because of type mismatch.
Point p = box.getSize();
Window
could break the encapsulation
of Point
objects.
For example, the field x
is private in Point
loaded by PL.
However, the Window
class could
directly access the value of x
if L loads Point
with the following definition:
public class Point {
public int x, y; // not private
public int getX() { return x; }
:
}
Sheng Liang and Gilad Bracha,
"Dynamic Class Loading in the Java Virtual Machine",
ACM OOPSLA'98, pp.36-44, 1998.
3.3 Using
javassist.Loader
javassist.Loader
. This class loader uses a
javassist.ClassPool
object for reading a class file.
javassist.Loader
can be used for loading
a particular class modified with Javassist.
import javassist.*;
import test.Rectangle;
public class Main {
public static void main(String[] args) throws Throwable {
ClassPool pool = ClassPool.getDefault();
Loader cl = new Loader(pool);
CtClass ct = pool.get("test.Rectangle");
ct.setSuperclass(pool.get("test.Point"));
Class c = cl.loadClass("test.Rectangle");
Object rect = c.newInstance();
:
}
}
test.Rectangle
. The
superclass of test.Rectangle
is set to a
test.Point
class. Then this program loads the modified
class, and creates a new instance of the
test.Rectangle
class.
javassist.Loader
.
The added event listener is
notified when the class loader loads a class.
The event-listener class must implement the following interface:
public interface Translator {
public void start(ClassPool pool)
throws NotFoundException, CannotCompileException;
public void onLoad(ClassPool pool, String classname)
throws NotFoundException, CannotCompileException;
}
start()
is called when this event listener
is added to a javassist.Loader
object by
addTranslator()
in javassist.Loader
. The
method onLoad()
is called before
javassist.Loader
loads a class. onLoad()
can modify the definition of the loaded class.
public class MyTranslator implements Translator {
void start(ClassPool pool)
throws NotFoundException, CannotCompileException {}
void onLoad(ClassPool pool, String classname)
throws NotFoundException, CannotCompileException
{
CtClass cc = pool.get(classname);
cc.setModifiers(Modifier.PUBLIC);
}
}
onLoad()
does not have to call
toBytecode()
or writeFile()
since
javassist.Loader
calls these methods to obtain a class
file.
MyApp
with a
MyTranslator
object, write a main class as following:
import javassist.*;
public class Main2 {
public static void main(String[] args) throws Throwable {
Translator t = new MyTranslator();
ClassPool pool = ClassPool.getDefault();
Loader cl = new Loader();
cl.addTranslator(pool, t);
cl.run("MyApp", args);
}
}
% java Main2 arg1 arg2...
MyApp
and the other application classes
are translated by MyTranslator
.
MyApp
cannot
access the loader classes such as Main2
,
MyTranslator
, and ClassPool
because they
are loaded by different loaders. The application classes are loaded
by javassist.Loader
whereas the loader classes such as
Main2
are by the default Java class loader.
javassist.Loader
searches for classes in a different
order from java.lang.ClassLoader
.
ClassLoader
first delegates the loading operations to
the parent class loader and then attempts to load the classes
only if the parent class loader cannot find them.
On the other hand,
javassist.Loader
attempts
to load the classes before delegating to the parent class loader.
It delegates only if:
get()
on
a ClassPool
object, or
delegateLoadingOf()
to be loaded by the parent class loader.
javassist.Loader
.
3.4 Writing a class loader
import javassist.*;
public class SampleLoader extends ClassLoader {
/* Call MyApp.main().
*/
public static void main(String[] args) throws Throwable {
SampleLoader s = new SampleLoader();
Class c = s.loadClass("MyApp");
c.getDeclaredMethod("main", new Class[] { String[].class })
.invoke(null, new Object[] { args });
}
private ClassPool pool;
public SampleLoader() throws NotFoundException {
pool = new ClassPool();
pool.insertClassPath("./class"); // MyApp.class must be there.
}
/* Finds a specified class.
* The bytecode for that class can be modified.
*/
protected Class findClass(String name) throws ClassNotFoundException {
try {
CtClass cc = pool.get(name);
// modify the CtClass object here
byte[] b = cc.toBytecode();
return defineClass(name, b, 0, b.length);
} catch (NotFoundException e) {
throw new ClassNotFoundException();
} catch (IOException e) {
throw new ClassNotFoundException();
} catch (CannotCompileException e) {
throw new ClassNotFoundException();
}
}
}
MyApp
is an application program.
To execute this program, first put the class file under the
./class
directory, which must not be included
in the class search path. Otherwise, MyApp.class
would
be loaded by the default system class loader, which is the parent
loader of SampleLoader
.
The directory name ./class
is specified by
insertClassPath()
in the constructor.
You can choose a different name instead of ./class
if you want.
Then do as follows:
% java SampleLoader
MyApp
(./class/MyApp.class
) and calls
MyApp.main()
with the command line parameters.
MyApp
class in a name space separated from the name space
that the class SampleLoader
belongs to because the two
classes are loaded by different class loaders.
Hence, the
MyApp
class cannot directly access the class
SampleLoader
.
3.5 Modifying a system class
java.lang.String
cannot be
loaded by a class loader other than the system class loader.
Therefore, SampleLoader
or javassist.Loader
shown above cannot modify the system classes at loading time.
hiddenValue
to java.lang.String
:
ClassPool pool = ClassPool.getDefault();
CtClass cc = pool.get("java.lang.String");
CtField f = new CtField(CtClass.intType, "hiddenValue", cc);
f.setModifiers(Modifier.PUBLIC);
cc.addField(f);
cc.writeFile(".");
"./java/lang/String.class"
.
MyApp
with this modified String
class, do as follows:
% java -Xbootclasspath/p:. MyApp arg1 arg2...
MyApp
is as follows:
public class MyApp {
public static void main(String[] args) throws Exception {
System.out.println(String.class.getField("hiddenValue").getName());
}
}
String
class is correctly loaded,
MyApp
prints hiddenValue
.
rt.jar
should not be
deployed as doing so would contravene the Java 2 Runtime Environment
binary code license.
3.6 Reloading a class at runtime
javassist.tools.HotSwapper
.
Java(TM) is a trademark of Sun Microsystems, Inc.
Copyright (C) 2000-2014 by Shigeru Chiba, All rights reserved.


{% extends "account/base.html" %} {% block head_title %}{{ gettext("Verify this Association") }}{% endblock %} {% block body %} {% set user_display = user_display(request.user) %}
{% trans %}You have begun to associate {{ specific_openid }} with your existing account. This will allow you to sign in as {{ user_display }} using that OpenID. Click below to verify that association.{% endtrans %}
{% endblock %}


@* * Copyright 2021 HM Revenue & Customs * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *@ @import uk.gov.hmrc.eoricommoncomponent.frontend.config.AppConfig @import uk.gov.hmrc.eoricommoncomponent.frontend.models.Service @import uk.gov.hmrc.eoricommoncomponent.frontend.views.html._ @import uk.gov.hmrc.eoricommoncomponent.frontend.views.ServiceName._ @this(layout_di: layout, appConfig: AppConfig, feedback_di: helpers.feedback) @(eori: String, service: Service)(implicit messages: Messages, request: Request[_]) @layout_di(messages("eds.existing-eori.enrolment.confirmation.title")) {
@messages("cds.reg.existing.outcomes.success.eori.number")
@eori
@messages("eds.existing-eori.enrolment.confirmation.para1", messages(longName))


Use api settings "animate" true or false - will do or not do the animation. 'initial' - will do only first time the animation.


{{ define "main" }}
Balanced control between App Devs and Operators.
Ensure apps meet security and compliance requirements.
Perform upgrades with minimal effort and intervention.
Buildpacks were first conceived by Heroku in 2011. Since then, they have been adopted by Cloud Foundry and other PaaS such as Google App Engine, Gitlab, Knative, Deis, Dokku, and Drie.
The Cloud Native Buildpacks project was initiated by Pivotal and Heroku in January 2018 and joined the Cloud Native Computing Foundation in October 2018. The project aims to unify the buildpack ecosystems with a platform-to-buildpack contract that is well-defined and that incorporates learnings from maintaining production-grade buildpacks for years at both Pivotal and Heroku.
Cloud Native Buildpacks embrace modern container standards, such as the OCI image format. They take advantage of the latest capabilities of these standards, such as cross-repository blob mounting and image layer "rebasing" on Docker API v2 registries.
Getting Started
The fastest way to try Cloud Native Buildpacks is via the pack
CLI.
Try out our tutorial to get started quickly!


V.O. SCRIPT:
Rachel does not dream. Rachel does not sleep. Rachel does not wake.
Rachel feels! All the time!
Rachel Head has a direct sense feed with Reinhardt Emotive FPS Blending™ for stunning clarity and total sensory presence. With the entire cultural library at her fingertips, Rachel can put herself into any scenario and create precision mixes at speed-of-mind. Watch as she blends Beethoven's 5th Symphony with the asteroid orbital catalogue, the 2018 World Cup game and the hot new anal cumming video from Angelica Eleenya.
What mastery!
See the subtle crafting and non-stuttering blends?
That's because Reinhardt's proprietary technology blend-splits 240 visual FPS on the fly to create an eye-popping visual stream of over 1000 FPS, while simultaneously delivering 60 tactile FPS and 60 olfactory FPS. Now this is salvation!
But, hey, forget the specs. Check out the feelings! Her Holocaust Child Victim Disco Muscle Thumps have walls around the world shedding tears and making those real feels. You can't fake this stuff! Are you tired of distant, deadened emotions? Reinhardt Emotive FPS Blending™ give you realistic, immersive feelings, without excess rumination or thought-linger. This kind of subtlety just isn't possible at ordinary 240 FPS. That's the difference for Rachel. That can be the difference for you.
Rachel does not dream. Rachel does not sleep. Rachel does not live. Rachel does not die.
Rachel feels.
Can you?


Nginx doesn’t support loadable modules such as some other web servers do, so in order to install Nginx with Passenger support, it must be recompiled.
Do you want this installer to download, compile and install Nginx for you?
<yellow>1. Yes: download, compile and install Nginx for me. (recommended)</yellow> The easiest way to get started. A stock Nginx <%= @nginx_version %> with Passenger support, but with no other additional third party modules, will be installed for you to a directory of your choice. <yellow>2. No: I want to customize my Nginx installation. (for advanced users)</yellow> Choose this if you want to compile Nginx with more third party modules besides Passenger, or if you need to pass additional options to Nginx's 'configure' script. This installer will 1) ask you for the location of the Nginx source code, 2) run the 'configure' script according to your instructions, and 3) run 'make install'.
Whichever you choose, if you already have an existing Nginx configuration file, then it will be preserved.


Make a program that makes the robot run 1.5 meters with a velocity of 0.3 m/s and then turn around and go back to the starting point.
Link to GitHub repositoryfwd 1.5 @v0.3
turn 180
fwd 1.5
Write a program that makes the robot run in a rectangle with the side length 1m and 0.3 m.
Link to GitHub repositoryfwd 1
turn 90
fwd 0.3
turn 90
fwd 1
turn 90
fwd 0.3
turn 90
Make a program that makes the robot run 0.75 m forward and the run in a square with round corners. The side lengths should be 0.3 m and the turning radius should be 0.3 m.

Link to GitHub repositoryfollowline "bm" :($drivendist>1)
stop
Make a program that makes the SMR follow the right branch of a y-fork. The SMR should stop after a suitable distance.
Link to GitHub repositoryfollowline "br" :($drivendist > 2)
stop
Make a program that makes the SMR follow the left branch of a y-fork. The SMR should stop after a suitable distance.
Make a program that makes the SMR follow a line and stop at a crossing line.
Link to GitHub repositoryfollowline "bl" :($crossingblackline > 0)
stop
Make a program that makes the SMR follow a line and stop if an obstacle is nearer than 0.4 m.
Link to GitHub repositoryfollowline "bm" :($irdistfrontmiddle < 0.4)
stop


Interface to 'Phylocom' (<http://phylodiversity.net/phylocom/>), a library for analysis of 'phylogenetic' community structure and character evolution. Includes low level methods for interacting with the three executables, as well as higher level interfaces for methods like 'aot', 'ecovolve', 'bladj', 'phylomatic', and more.
| Version: | 0.1.2 |
| Imports: | tibble, sys (≥ 1.1) |
| Suggests: | testthat, knitr, rmarkdown, ape |
| Published: | 2018-11-29 |
| Author: | Jeroen Ooms [aut],
Scott Chamberlain [aut, cre],
Cam Webb [cph] (Author of libphylocom (see AUTHORS and COPYRIGHT files
for details)),
David Ackerly [cph] (Author of libphylocom (see AUTHORS and COPYRIGHT
files for details)),
Steven Kembel [cph] (Author of libphylocom (see AUTHORS and COPYRIGHT
files for details)) phylocomr author details |
| Maintainer: | Scott Chamberlain <sckott at protonmail.com> |
| BugReports: | https://github.com/ropensci/phylocomr/issues |
| License: | BSD_2_clause + file LICENSE |
| URL: | https://github.com/ropensci/phylocomr |
| NeedsCompilation: | yes |
| Language: | en-US |
| Materials: | README NEWS |
| CRAN checks: | phylocomr results |
| Reference manual: | phylocomr.pdf |
| Vignettes: |
Introduction to the phylocomr package |
| Package source: | phylocomr_0.1.2.tar.gz |
| Windows binaries: | r-devel: phylocomr_0.1.2.zip, r-release: phylocomr_0.1.2.zip, r-oldrel: phylocomr_0.1.2.zip |
| OS X binaries: | r-release: phylocomr_0.1.2.tgz, r-oldrel: phylocomr_0.1.2.tgz |
| Old sources: | phylocomr archive |
| Reverse imports: | brranching |
Please use the canonical form https://CRAN.R-project.org/package=phylocomr to link to this page.


Since interval data is numeric, you can perform any mathematical operation, but interval data does not have any meaningful zero. For example, suppose Sunday at midnight, there was an accident in your neighborhood, and as a result, there was massive traffic in your neighborhood. One way to measure the timing is through a 24-hour clock and say that your neighborhood experienced unusual traffic at 0:00 AM on Sunday. Here zero does not mean that there is an absence of time. Zero is just the measure of the time of the day using a 24-hour clock.
in-context


eventbrite
Businessmodel of Eventbrite
Customer Segments
Eventbrite serves two customer segments, consisting of event organizers looking to increase the visibility of their event (which includes, but is not limited to: concerts, contests, parties, classes and workshops) and individuals, who wish to attend advertised events of interest.
Value Propositions
From the very beginning the strongest asset of Eventbrite has been its continuous dialogue and involvement with customers and users as well as active implementation of their feedback into the development of the platform and company services. Because the brand is built on user feedback – it is highly reactive, functional and easy-to-use, which increases its popularity with customers who’ve actively participated in its design.
On the other hand, Eventbrite offers viable opportunities to people of all social backgrounds to create and advertise events of any type, which can become a source of income. In this way the platform stimulates individuals to use it not only for recreational purposes (e.g. to locate a local event of interest), but for work and self-promotion as well.
Channels
Eventbrite has relied on a heavy social network presence as well as extensive word-of-mouth campaigns to grow its customer base. Because its product integrates customer reviews with the very service (event management) they offer – this has resulted in an unparalleled visibility on Google and other search engines due to the large volume of indexed user reviews of events marketed on the platform.
Awareness of Eventbrite has also been boosted by its move to open its API to developers for the introduction of new features, which make its product increasingly tailored to the needs and specifics of targeted consumer groups.
Customer Relationship
Eventbrite is an entirely self-service reliant platform, where users create, promote, manage, and host a number of live events. The entire interface of the website is built to be as functional and user-friendly as possible and there are a wide number of options to choose from.
Key Activities
Eventbrite focuses on the design and provision of its functional web platform and development of mobile applications that allow users to create, share, find and advertise a wide range of live events.
Its focus is on self-servicing the ‘people’ part of the ticketing industry. Event promotion on the company’s social media accounts is another area which the company is actively working on.
Key Partners
Recently, Eventbrite struck a successful partnership with Batchbook – a dynamic platform that enables companies to better manage their existing customer relationships as well as form new ones.
This tool has integrated seamlessly with Eventbrite’s creative approach to focus on the ‘human’ element in its business process.
Key Resources
One of Eventbrite’s highest regarded resources is its talent capital or the so-called ‘britelings’ –people who actively promote the brand over a number of social media channels. Another key resource includes the early adopted group of tech bloggers (IT technicians) as well as developers who contributed to the new features of the company’s API.
The company’s IT infrastructure is its key asset and resource as it’s the core of Eventbrite’s business and service distribution.
Cost Structure
Immediately upon securing funding in 2009 Eventbrite directed most of it into the development and growth of its human (talent) capital and expanded its working team from 3 to 15 persons.
It currently employs 450+ people across 8 international offices and continues to invest in its employees and corporate environment (as evidenced by being voted Best Places to Work in San Francisco six years running). In this sense the salary of its staff is the biggest block of Eventbrite’s cost structure followed by system maintenance and app development.
Revenue Streams
Eventbrite currently has two revenue streams – its free version for hosted events that are free of charge, which translates into increased visibility. A large percentage of free event organizers were reported to go on and become paid ones, thus saving the company money on marketing and sales.
Additionally, the model of Eventbrite relies on charging event organizers only per sold ticket rather than a subscription-based plan.
Because it was the first major player in this market in the US, the company saw some benefits of its innovative approach, but is currently competing against several alternative companies and services.


Spotlight: Discotech - The Best Vegas Nightlife App
Find the right nightlife experience in Las Vegas with Discotech.
by MagneticLooking to go to Vegas but don’t know where to start? Don’t worry – Discotech’s got you covered. Discotech is a free mobile app that allows you to see where your favorite artists / DJs are performing, sign up for free / discounted guest lists, get discounted tickets & promo codes, and book table service at the hottest clubs in Las Vegas.
Upcoming Events:
With over 20 different clubs and pool parties, deciding where to go isn’t an easy task. Discotech lets you easily see upcoming events in Vegas, who’s playing on which dates, see where your friends are going, and browse pictures of each club with a few swipes on your phone.
Sign Up For Free Guest Lists
Looking to do Vegas on a budget? Almost all the clubs in Las Vegas have a guest list – free before a certain time. Some guest lists require even ratio of guys to girls. Some guest lists come with free drink tickets. All the details are on the app!
Book Table Service
For those of you looking to drop some cash – bottle service in Vegas is definitely a fantastic option! Whether you’re looking for a Cabana at Encore Beach Club or a dance floor table at Omnia – Discotech’s got you covered every step of the way.
In addition, Discotech has a variety of Las Vegas nightlife guides to answer any questions you might have – for example: What are the best EDM clubs in Las Vegas? What are the best hip-hop pool parties? What are the best Vegas Nightswims?
In addition to Vegas, you can also browse events and clubs in over 100 cities worldwide, including: San Diego, Brooklyn, New York, Boston, Cancun, Miami, Houston, Scottsdale, Tokyo, Toronto, Vancouver, Washington DC, Amsterdam, Chicago, and more!
What are you waiting for? Go download the app and make your night legendary!
This is sponsored content


Linux provides many system calls for userspace. But numbers used for them differ between architectures. This page was created to help developers find those values.
But there is another issue. Some of system calls got dropped during Linux development, some got replaced by newer ones. Several architectures got added into kernel later and their maintainers decided to not bother with supporting obsoleted system calls. They are marked with "-1" value in table below.
There are few features you can use:
man 2 unimplemented
are not listedSystem calls table is maintained by Marcin Juszkiewicz — AArch64/Arm developer working at Red Hat as Linaro assignee.
Sources used to generate table are available in git repository at github. Patches are always welcomed.
If this table helped you in some project then please leave a comment in issue on GitHub.
Table generated on $generate_time using data from $kernel_version kernel source.
| system call | $archs_header
|---|


Table Structure
Relational Databases in SQL are created in the form of rows and columns. Rows represent an instance or entry in the database, and the columns represent an attribute of that entry. In an optimal table, every entry is unique. If a table has a column with many repeated entries, that indicates that a new table should be made containing those entries.
Table Relationships
There are three general kinds of table relationships, one-to-many, many-to-many, and one-to-one. In our examples we will cover multiple use-cases for relational databases.
- One-to-Many - In a "class roster" database, a teacher may teach zero or more classes, while a class is taught by one (and only one) teacher. Take note that for every value in the parent table, there could be zero, one, or more rows in the child table. For every value in the child table, there is one and only one row in the parent table.
- Many-to-Many - In a "product sales" database, a customer's order may contain one or more products; and a product can appear in many orders. To support many-to-many relationship, we need to create a third table (known as a junction table).The many-to-many relationship is, in fact, implemented as multiple one-to-many relationships, with the introduction of the junction table.
- One-to-One - In a "product sales" database, a product may have optional supplementary information. Keeping them inside a single table results in many empty spaces (in those records without these optional data). Furthermore, these large data may degrade the performance of the database. Instead, we can create another table to store the optional data. A record will only be created for those products with optional data.
Keys
In the relational model, a table cannot contain duplicate rows, because that would create ambiguities in retrieval. To ensure uniqueness, each table should have a column (or a set of columns), called primary key, that uniquely identifies every records of the table. A primary key is called a simple key if it is a single column; it is called a composite key if it is made up of several columns. In choosing a primary key, it should be simple and familiar, should not change, and is best to use an integer for efficiency. A foreign key of a child table is a primary key of a parent table, used to reference the parent table. The assumption that the primary key is an auto-incrementing integer called id is baked deeply into Rails. Most web applications follow this convention.
Queries
Select
The SELECT statement is used to select data from a database. The result is stored in a result table, called the result-set.
SELECT column_name,column_name FROM table_name;
Order By
The ORDER BY keyword is used to sort the result-set by one or more columns. The ORDER BY keyword sorts the records in ascending order by default. To sort the records in a descending order, you can use the DESC keyword.
SELECT column_name FROM table_name ORDER BY column_name ASC|DESC;
Where
The WHERE clause is used to extract only those records that fulfill a specified criterion.
SELECT column_name FROM table_name WHERE column_name operator value;
Like
The LIKE operator is used to search for a specified pattern in a column.
SELECT column_name(s) FROM table_name WHERE column_name LIKE pattern;
Joins
An SQL JOIN clause is used to combine rows from two or more tables, based on a common field between them. The most common type of join is: SQL INNER JOIN (simple join). An SQL INNER JOIN return all rows from multiple tables where the join condition is met.
SELECT Tables1.ID, Tables2.colum_name, Tables1.column_name FROM Tables1 INNER JOIN Tables2 ON Tables1.table2_ID=Tables2.ID;
- INNER JOIN: Returns all rows when there is at least one match in BOTH tables
- LEFT JOIN: Return all rows from the left table, and the matched rows from the right table
- RIGHT JOIN: Return all rows from the right table, and the matched rows from the left table
- FULL JOIN: Return all rows when there is a match in ONE of the tables


Add the following code block to your .htaccess file to add an extra layer of security. Any attempts to access the .htaccess file will result in a 403 “Forbidden” response. Learn more.
# secure .htaccess file
<Files .htaccess>
Order allow,deny
Deny from all
</Files>
Of course, your first layer of defense to protect .htaccess (and other sensitive) files involves setting the file permissions via CHMOD to be as restrictive as possible.


This page shows a few of the common ways in which you might want to style links. To see how each is accomplished, right click on the page and select "View Page Source" on the context menu.
Site Navigation
Your main site navigation links are typically marked up as links inside an unordered list, inside a nav element. Using CSS, we can transform those into something that looks like a navigation bar.
And here's the same nav, but with a tab look rather than a navbar look. The only change in the markup is a class attribute set to "tabs" instad of "navbar" and some CSS that uses the class to apply different effects.
Nicer Links in the Body
A common styling for links is to make both visited and non-visited links a slightly lighter color than black, and underlined only when the mouse is hovering over them or when activated. View the source of this page to see how that is done.


I am a freelance designer and developer with experience in web and mobile.
I live and work in Chicago, Illinois, overlooking the Blue Line and the Chicago River.
Click here if you're curious how I ended up here.
I am a freelance designer and developer with experience in web and mobile.
I live and work in Chicago, Illinois, overlooking the Blue Line and the Chicago River.
Click here if you're curious how I ended up here.


Automatic Clicker Options
activate automatic clicking
every 30 sec
every 1 min
every 2 min
every 5 min
every 10 min
every 30 min


It's more like Connect, but a lot of the Express goodies were moved to the middleware level in Koa to help form a stronger foundation. This makes middleware more enjoyable and less error-prone to write, for the entire stack, not just the end application code.
Typically many middleware would re-implement similar features, or even worse incorrectly implement them, when features like signed cookie secrets among others are typically application-specific, not middleware specific.
No, just a different take on similar functionality now that async functions allow us to write code with fewer callbacks. Connect is equally capable, and some may still prefer it, it's up to what you prefer.
No - out of the box Koa has no form of routing, however many routing middleware are available: https://github.com/koajs/koa/wiki
Koa is a pretty large departure from what people know about Express, the design is fundamentally much different, so the migration from Express 3.0 to this Express 4.0 would effectively mean rewriting the entire application, so we thought it would be more appropriate to create a new library.
Koa uses its own custom objects: ctx
, ctx.request
, and ctx.response
.
These objects abstract node's req
and res
objects with convenience methods and getters/setters.
Generally, properties added to these objects must obey the following rules:
Many of ctx.request
and ctx.response
's properties are delegated to ctx
.
If it's a getter/setter, then both the getter and the setter will strictly
correspond to either ctx.request
or ctx.response
.
Please think about these rules before suggesting additional properties.


Interactive Information Design
Week one: Storytelling with data
Heather Battaglia (or Billings) / @hbillings
Hello There
My name is Heather and I will be your host this afternoon. Please keep your arms and legs inside the class at all times.
Today's agenda
- Class overview
- Introductions
- Warm-up exercise: Driving is why you're fat (GOOD Magazine)
- Lecture: Introduction to information design
- Closing lab & discussion: Strife in the Middle East
Canvas Overview
Canvas Overview
Canvas Overview
Canvas Overview
Today's agenda
- Class overview
- Introductions
- Warm-up exercise: Driving is why you're fat (GOOD Magazine)
- Lecture: Introduction to information design
- Closing lab & discussion: Strife in the Middle East
http://goo.gl/forms/pK9LfxM0XJ
Today's agenda
- Class overview
- Introductions
- Warm-up exercise: Driving is why you're fat (GOOD Magazine)
- Lecture: Introduction to information design
- Closing lab & discussion: Strife in the Middle East
GOOD Magazine Lab
You're a top editor for GOOD magazine, and a few weeks ago, you signed off on the following pitch for an infographic in an editorial meeting:
"There’s this awesome study that basically shows that driving is a major contributing factor to obesity. So I want to visualize that data and show that relationship."
The design's in your inbox, and you've got 20 minutes to prep for a meeting.
Objectives
Evaluate the graphic on the following criteria:
- Editorial integrity (you’ll need to take a look at the source of this data)
- How well this infographic fosters efficient and effective understanding of the data.
Prep for the meeting:
- List any misgivings you have or questions you have for the designer.
- For each criticism, offer an alternative.
Today's agenda
- Class overview
- Introductions
- Warm-up exercise: Driving is why you're fat (GOOD Magazine)
- Lecture: Introduction to information design
- Closing lab & discussion: Strife in the Middle East
Information design is the practice of presenting information in a way
that fosters efficient and effective understanding of it. The term has
come to be used specifically for graphic design for displaying
information effectively, rather than just attractively or for artistic
expression. Information design is closely related to the field of data
visualization and is often taught as part of graphic design courses.
(Thanks, Wikipedia.)
Excellence in statistical graphics consists of complex
ideas communicated clarity, precision, and efficiency.
—Edward Tufte
Graphical displays should:
- show the data
- induce the viewer to think about the substance rather than about methodology, graphic design, the technology of graphic production, or something else
- avoid distorting what the data have to say
- present many numbers in a small space
Tufte, "The Visual Display of Quantitative Information"
Graphical displays should:
- make large data sets coherent
- encourage the eye to compare different pieces of data
- reveal the data at several levels of detail, from a broad overview to the fine structure
- serve a reasonably clear purpose: description, exploration, tabulation, or decoration
- be closely integrated with the statistical and verbal descriptions of a data set.
Tufte, "The Visual Display of Quantitative Information"
Napoleon's March into Russia
Charles Joseph Minard
The informations used for drawing the map were taken from the works of Messrs. Chiers, de Ségur, de Fezensac, de Chambray and the unpublished diary of Jacob, pharmacist of the Army since 28 October.
In order to facilitate the judgement of the eye regarding the diminution of the army, I supposed that the troups under Prince Jèrôme and under Marshal Davoust, who were sent to Minsk and Mobilow and who rejoined near Orscha and Witebsk, had always marched with the army.
—Charles Joseph Minard
Good data visualization
tells a good story.

- Craft a visual lede.
- Provide the context. (Why does the data behave this way? What's behind it?)
- Enable a deep dive.
- Data at a glance, and data you can sit with.
- Wow! … Huh? vs. Huh? … Wow.
Bar Charts
Basic categorical comparison
Bar Charts
Bar Charts
Pie Charts
How data breaks down in different groups.
(Almost never do this.)
Pie Charts
A, B, C: Three points in time
1,2,3,4,5: Political candidates share of the vote
Pie Charts
A, B, C: Three points in time
1,2,3,4,5: Political candidates share of the vote
Pie Charts
Best for simple data
Scatterplots
Used to spot or illustrate trends
(Requires knowledge of information)
Line graphs
Trends over time
Area charts
Line graphs, but filled in
Colored area corresponds to data
Change in size over time
Bubble charts
Area corresponds to size of data
Maps
Geography is part of the story
Maps
Geography is not always the point of the story.
Maps
Like pie charts, maps can be difficult to interpret.
Maps
Timelines
Event-based over time
Venn diagrams
Area charts that intersect
Highlights commonality
Glyphs
Individual glyphs relate to number of data
Glyphs
Flow charts
Depict evolution or decision-making tree
Set goals before you begin...
- Compare year to year
- Illustrate trends of the past 10 years
- Display data points for individual years
...then measure your illustrations against these goals.
- What’s your first impression? (Visual headline!)
- Are things better or worse than they were five years ago?
- What was the trade gap in 1998?
Things to consider this quarter:
- You must know the story.
- To know the story, you must know the data.
- Don’t leave the analysis to us! Annotate. Walk us through. Break it down.
- Tiered content — visual headline, central narrative (cause/effect), detailed reading (individual data pts.)
- You are not your target audience. Test, iterate, test.
Things to consider this quarter:
- Hierarchy
- Titles and labels
- Axes
- Use of color — make it meaningful
- Different charts for different stories
Today's agenda
- Class overview
- Introductions
- Warm-up exercise: Driving is why you're fat (GOOD Magazine)
- Lecture: Introduction to information design
- Closing lab & discussion: Strife in the Middle East
Strife & power in the new Middle East
Working in teams of 3-4, and using the article "Strife and Power in the New Middle East" as your guide, create a proposal for an information graphic. Set goals for the story before you begin, and work on a series of sketches together. Weigh each of them against your set goals. Come up with the solution you think is best and be ready to present to the group.
One solution...


Simple Jekyll tutorial with Github Pages
I’m absolutely loving my new Jekyll blog, but getting it setup wasn’t that easy. Finding useful and accessible information on how everything works was very difficult. In the end, faithfully following tutorials and crashing around on Github resulted in this functional blog.
This post will provide a Jekyll blog setup tutorial assuming very little knowledge of the languages and technologies it is built on (Github, git, HTML, Markdown, Jekyll, Ruby, Liquid templates). Casually surveying friends and colleagues, it seems that many people have heard of Github Pages, but haven’t explored it for a number of reasons. Here is what I hope to accomplish:
- Help you get setup with everything you will need before you start building a Jekyll blog
- Build a clean, professional site that let’s you show off your resume, link to your social media accounts and build blog posts to catalog your ideas and share your opinions
- Provide links to more in depth resources on the basics as well as links to more advanced topics
- (I’ve written this tutorial assuming you are using an Apple computer)
The first few steps are the easiest. So let’s jump right in!
Step 1: Github Pages
Check out the instructions that Github offers on their Github Pages site. If you don’t already have a Github account, get one first.
The username you choose on Github will be the first part of the URL that your site uses, but you can change this later. For example, if your name is Art Vandelay and you select artvandelay as your Github username, your site’s URL will be artvandelay.github.io.
As the Github pages guide instructs you to do, create a repository titled username.github.io (where username is your Github account name). You don’t need to initialize the repository with the ReadMe.md file. This step is very important and any variation in the name of this repository will not result in a successful Github Pages site.
Select “A terminal” when you see the question “What git client are you using?” (it should already be selected). You may be asking yourself, “what is git?” For now, just think of it as a version control manager.
This next step is where I ran into a few difficulties, so I’m going to clarify a few things. Eventually, your newly created repository username.github.io will house all of the files that will run your blog, including the HTML, CSS files, etc. What you need to do next is create a folder on your computer where you will keep a copy of all of your site’s files. You will use git to push files from this local folder on your computer to your repository that is ‘hosting’ your Jekyll site. We will talk about what “using git” means in just a bit.
I keep mine in a folder at the location ~/Github/briancaffey.github.io
(where ~
references my ‘Home’ folder). If you are not familiar with Github, read the next few paragraphs carefully before doing anything. The command listed in step 2 of the Github Pages instructions tells you to run the following command in your terminal:
$ git clone https://github.com/username/username.github.io
This will create a file named username.github.io inside whatever folder you are currently in. Open up terminal and type in the following command, then press enter. (Don’t type the $
, just type pwd
; the $
signifies that you are in the terminal).
$ pwd
User/yourmaclogin/
You should see a file path, something like Users/yourmaclogin
on the following line. pwd
means “Print Working Directory”, and that’s just what you did. Your “working directory” is the directory you are “at” (sorry about the poor English, but this is the easiest way to communicate this idea).
So, you should choose the folder that you want to “clone” (copy) your empty username.github.io repository into. We will learn two more commands that will help us “navigate” our file system.
Suppose you have a folder named main
with the following files inside that folder: sub1
and sub2
. Inside sub1
and sub2
, suppose you have some text files: sub1_example.txt
inside the folder sub1
and sub2_example.txt
inside sub2
. If your current working directory is main
, then we can list all of the file and folder that are directly inside of main
with the following command:
$ ls
sub1 sub2
ls
is short for “list” and it simply lists files and folders that are directly inside a file. It won’t list either of the text files, because those are not directly inside of main
, even though they technically are located “within” it.
In order to see these text files, you will need to change our working directory. You can do this with the “change directory” command that is conveniently called cd
:
$ cd sub1
$ ls
sub1_example.txt
Great! Now what about sub2? The cd <folder>
command takes us inside a folder that is in our working directory. It can also take us to the folder that contains out working directory. Check out this example:
$ cd ..
$ pwd
/main
cd ..
takes us from sub1
to main
. If you are not sure where you are, just run the ls
command and you can see the contents of your working directory.
Ok, once you have a handle on this, run the following command in the terminal. Be sure to replace username with your actual Github username in both places, otherwise you will see an error. So go ahead and run:
$ git clone https://github.com/username/username.github.io
This concludes the first step, let’s move on to Step 2: Jekyll.
Step 2: Jekyll
So what exactly is Jekyll? Here an explanation from Jekyll’s website:
Jekyll is a simple, blog-aware, static site generator. It takes a template directory containing raw text files in various formats, runs it through a converter (like Markdown) and our Liquid renderer, and spits out a complete, ready-to-publish static website suitable for serving with your favorite web server. Jekyll also happens to be the engine behind GitHub Pages, which means you can use Jekyll to host your project’s page, blog, or website from GitHub’s servers for free.
This explanation didn’t make much sense to me when I first attempted to make my Jekyll site, so let me try to explain it in another way. Jekyll is a system of folders and files that allow you to make simple web pages. When you put this system of folders and file system on Github, it generates a website that is absolutely free. Instead of writing HTML, you write content in template documents (Markdown files) that are automatically converted to beautiful HTML pages with mobile-friendly responsiveness.
Let’s go ahead with out website setup! Go back to Jekyll’s website and look at the very simple instructions they provide for quick-start installation, but don’t run them just yet!
$ gem install jekyll
$ jekyll new my-awesome-site
$ cd my-awesome-site
$ jekyll serve
# => Now browse to http://localhost:4000
We will be modifying these commands slightly to get our website up and running. The first command installs Jekyll onto your computer. Go ahead and do this, then navigate to your username.github.io folder that you have cloned from Github in Step 1. Run the pwd
command to make sure you are in the correct working directory. The needs to be empty for this next step to work, so go ahead and run our ls
command to make sure that there is nothing inside.
At this point we are ready to install Jekyll! Run the following command:
$ jekyll new
Then run the ls
command and you should see the following:
$ ls
_config.yml _layouts _sass css index.html
_includes _posts about.md feed.xml
You have installed Jekyll! At this point we can give it a test run! We are going to view our new website in our browser, but we will be running the site locally (i.e. it will not be available at username.github.io).
The next command will start running our website:
$ jekyll serve
After you run this command, several lines will be printed out in the terminal. Look for one that looks like this:
Server address: http://<IP_ADDRESS>:4000/
This address may be different on your computer, so copy it exactly from your terminal and run it in your browser, or run localhost:40001
in your browser if that doesn’t work. You should see your website!
For now it is mostly filler content, but we will learn how to edit this content in the next few steps.
Step 3: Github
This next step will move your entire website onto the web and will make it available at username.github.io.
Confirm you are still in you username.github.io folder (pwd
command) and run the following commands:
$ git init
$ git add .
$ git commit -m "initial commit"
$ git push origin master
You will have to enter your Github username and password for the last step to work. Now, if you did not get any error messages in your terminal after running the above commands, open up username.github.io in your browser. You, and anyone with the link, should be able to see your website!
As you make changes and additions to the username.github.io file system, you can repeat this step to refresh the content of your website.
Step 4: Making Pages in Jekyll
At this point, the first thing I wanted to do was to create both a simple “Contact” page and a “Resume” page. The process of creating pages is simple, but there are few tutorials that explain what the simple process is in its entirety. Here’s how I understand it:
Create a “top level” Markdown file in our username.github.io folder. “Top level” means that it is directly inside our username.github.io file and not in any subfolders. To create this folder, you will need a text editor. The number one search result for text editor in Google is Sublime Text, which is the text editor that I prefer. You can open your entire username.github.io folder with Sublime Text to easily move between files.
Let’s create a contact page first. Create a new file called contact.md
. The .md
stands for Markdown and it is the type of file that you will be working with the most in Jekyll. Add the following content to this file:
---
layout: page
title: "Contact"
---
Hi, my name is Art Vandelay. Welcome to my website!
Follow me on twitter at [@artvandelay](http://www.twitter.com)
Connect with me on [LinkedIn](http://www.linkedin.com)
Save this file, and head back over to localhost:4000
, reload the page and check to see if your page was added to your site.
Our contact.md
file starts with something called Front Matter, enclosed between two ---
bars. In this space, you specify the type of page you are creating. In this example, wrote layout: page
because this is a regular page. In the following examples, we will set the layout
variable to post
when we want to create a blog post.
Links are pretty easy to make in Markdown. Simply wrap the clickable link text you want displayed in brackets, immediately followed by the URL in parentheses. For example, [Google](http://www.google.com)
would result in Google. Be sure to include http://
at the beginning of your links. If you don’t, it will create a link relative to the page. For example, [Google](google.com)
would result in username.github.io/google.com
which would not go anywhere.
For the next example, create a top-level folder in your username.github.io folder called docs
(or some other name) where you will store static files like PDFs for your site. Now put your resume in it. Next, copy the following code into a new top-level file in your username.github.io folder called resume
(not in the docs
folder you just created, we are making a page here just like we did with the “Contact” page).
---
layout: page
title: Resume
---
Here's a link to a PDF of [my resume](/docs/my_resume.pdf).
At this point it would be good to introduce the simple and powerful formating that you can do with Markdown. Suppose you want to include the text of your resume in a neatly organized way below the download link for your resume as I have done for my Resume page. Markdown makes this very easy.
There are many ways to structure and organize content in Markdown, so I’ll show you how I did it and point you in the direction of some useful resources and cheat sheets. Here is the Markdown file I used for my resume page, feel free to copy my exact formatting as I copied it from someone else! Also check out this Markdown cheat sheet.
Step 5: Making blog posts in Jekyll
Making blog posts in Jekyll is slightly different from making pages in Jekyll. There are a few things you need to do to create a blog post.
- Create a Markdown file with the following naming convention: YYYY-MM-DD-post-name.md
- In this file’s Front Matter, set the
layout
topost
by writinglayout: post
- Set the
date
andtitle
of the post in the Front Matter - Place this file in the
_posts
folder
You should see the blog post listed on your home page and your “Blog” page that comes pre-loaded with a new Jekyll site.
We will talk about how to change the layout of your sites homepage, pages and posts later on. The next step will show you how allow comments using Disqus on a per-post basis.
Step 6: Adding comments to your posts
To enable comments on your blog, I recommend using a free and popular comment service called Disqus.
To enable comments with Disqus, we need to explore a new folder in our file system. In the _includes
folder you will find a number of files that are “snippets” of HTML code including header.html
and footer.html
. _includes
is a folder where you will keep reusable snippets of code that will want to include in many different places in your site.
Let’s make a code snippet titled comments.html
. In this file, add the following code:
{% if page.comments %}
{% endif %}
Any code in between these two lines will be included if pages.comments
is set to true
. You will set this variable value in the Front Matter as you create new posts. Next, add the following code between these two lines above:
Pay attention to the line that reads:
You will need to replace YOUR_DISQUS_USERNAME
with the name you have selected for your Disqus account. Be sure to enclose it in single quotes.
Next we have to learn how to include this code snippet into all posts. Look in the _layouts
folder and open up the post.html
file.
This is a template document that will determine the format of each blog post. When we specified layout: page
in the Front Matter of our Resume and Contact pages, this caused Jekyll to use the page.html
layout. As I mentioned before, in our posts, we will specify layout: post
in the Front Matter of our posts to use the post.html
template.
In this layout, we will add one line of code right before the last line of the post.html
layout template directly above the closing </article>
tag:
{% include comments.html %}
Now, let’s make a new blog post. Title it something like 2016-03-18-my-first-post.md
. Let’s add Front Matter so Jekyll knows what to do with our post.
---
layout: post
title: My First Post
date: 2016-03-18
comments: true
---
This is the body of my first blog post on my Jekyll blog! I hope it gets some good comments!
Great, now you should have a new blog post with Disqus comments enabled on it. You may not be getting a lot of comments on your articles, but you still could have lots of readers. The next section will cover how to add Google Analytics to our site so we can easily track visitors and page views.
Step 7: Adding Google Analytics to your Jekyll blog
Now that we know how to include a short snippet of code in multiple pages on our blog, adding one more little snippet for Google to track page views will be very easy. If you don’t know about Google Analytics, it probably the most powerful tool for tracking visitors to your website. Google makes it very easy, and only requires that we include a short snippet of JavaScript on each page we want to track.
Let’s create another HTML snippet in our _includes
folder called google-analytics.html
. You are only going to put a tracking code that will be unique to your site. Head over to Google Analytics to get your tracking code. After filling out a few simple forms, you should get your tracking code. It should look something like this:
Next we will need to insert this google_analytics.html
snippet each page of our site. Doing this is very easy, just add {% include google_analytics.html %}
in between the opening <html>
and <body>
tags of the default.html
file in the _layouts
folder.
Conclusion
I hope you have found this tutorial helpful. At times I probably over-explained things, and there may be some areas that need clarification, so I’ll add updates and create more posts in the future as I learn more about Jekyll myself.
My Jekyll blog is big experiment. It’s been both challenging and fun, but most of all I love the fact that it is totally free. I hope that anyone reading this post who wants to put together a Jekyll blog hosted with Github Pages has success in doing so. Please let me know in the comments if there are any areas that I should change, elaborate on or take out. Thanks!


--- title: "Basics of Data Visualization and DAGs in R" subtitle: "Our first steps with `ggplot2` and `ggdag`" type: book weight: 5 output: blogdown:html_page: theme: journal highlight: tango df_print: paged toc: yes toc_float: collapsed: false ---
# Load packages. Install them first, in case you don't have them yet.
library(palmerpenguins) # To get our example's dataset
library(tidyverse) # To use dplyr functions and the pipe operator when needed
library(ggplot2) # To visualize data (this package is also loaded by library(tidyverse))
library(ggdag) # To create our DAGs
This week's tutorial will be divided in two broader camps.
ggplot
.ggplot2
ggplot2
is by far the most popular visualization package in R. ggplot2
implements the grammar of graphics to render a versatile syntax of creating visuals. The underlying logic of the package relies on deconstructing the structure of graphs (if you are interested in this you can read this article).
For the purposes of this introduction to visualization with ggplot, we care about the layered nature of visualizing with ggplot2
.
*This tutorial is based largely on chapters 7 to 10 from the QPOLR book
During this week, we will learn about the following building blocks:
The first building block for our plots are the data we intend to map. In ggplot2
, we always have to specify the object where our data lives. In other words, you will always have to specify a data frame, as such:
ggplot(name_of_your_df)
In the future, we will see how to combine multiple data sources to build a single plot. For now, we will work under the assumption that all your data live in the same object.
The second building block for our plots are the aesthetics. We need to specify the variables in the data frame we will be using and what role they play.
To do this we will use the function aes()
within the ggplot()
function after the data frame (remember to add a comma after the data frame).
ggplot(name_of_your_df, aes(x = your_x_axis_variable, y = your_y_axis_variable))
Beyond your axis, you can add more aesthetics representing further dimensions of the data in the two dimensional graphic plane, such as: size, color, fill, to name but a few.
The third layer to render our graph is a geomethic object. To add one, we need to add a plus (+) at the end of the initial line and state the type of geometric object we want to add, for example, geom_point()
for a scatter plot, or geom_bar()
for barplots.
ggplot(name_of_your_df, aes(x = your_x_axis_variable, y = your_y_axis_variable)) +
geom_point()
At this point our plot may just need some final thouches. We may want to fix the axes names or get rid of the default gray background. To do so, we need to add an additional layer preceded by a plus sign (+).
If we want to change the names in our axes, we can utilize the labs()
function.
We can also employ some of the pre-loaded themes, for example, theme_minimal()
.
ggplot(name_of_your_df, aes(x = your_x_axis_variable, y = your_y_axis_variable)) +
geom_point() +
theme_minimal() +
labs(x = "Name you want displayed",
y = "Name you want displayed")
For our very first plot using ggplot2
, we will use the penguins
data from last week.
We would like to create a scatterplot that illustrates the relationship between the length of a penguin's flipper and their weight.
To do so, we need three of our building blocks: a) data, b) aesthetics, and c) a geometric object (geom_point()
).
ggplot(penguins, aes(x = flipper_length_mm, y=body_mass_g)) +
geom_point()
EXERCISE:
Once we have our scatterplot. Can you think of a way to adapt the code to:
theme_minimal()
.ggplot(penguins, aes(x = flipper_length_mm, y=body_mass_g, color=species)) +
geom_point() +
theme_minimal() +
labs(x = "Flipper Length (mm)",
y = "Body mass (g)",
color = "Species")
{{% /spoiler %}}
If we are interested in plotting distributions of our data, we can leverage geometric objects, such as:
geom_histogram()
: visualizes the distribution of a single continuous variable by dividing the x axis into bins and counting the number of observations in each bin (the default is 30 bins).geom_density()
: computes and draws kernel density estimate, which is a smoothed version of the histogram.geom_bar()
: renders barplots and in plotting distributions behaves in a very similar way from geom_histogram()
(can also be used with two dimensions)This is a histogram presenting the weight distribution of penguins in our sample. .
ggplot(penguins, aes(x = body_mass_g)) +
geom_histogram()
EXERCISE:
Let's adapt the code of our histogram:
bins = 15
argument (type different numbers)fill = "#FF6666"
(type "red", "blue", instead of #FF6666)_density
and _bar
ggplot(penguins, aes(x = body_mass_g)) +
geom_histogram(bins = 15)
ggplot(penguins, aes(x = body_mass_g)) +
geom_histogram(bins = 25, fill = "#FF6666")
geom_density()
and geom_bar()
ggplot(penguins, aes(x = body_mass_g)) +
geom_density(alpha = 0.5, fill = "#FF6666")
ggplot(penguins, aes(x = body_mass_g)) +
geom_bar(fill = "#FF6666")
{{% /spoiler %}}
We can utilize graphs to explore how different variables are related. In fact, we did so before in our scatterplot. We can also use box plots and lines to show some of these relationships.
For example, this boxplot showcasing the distribution of weight by species:
ggplot(penguins, aes(x = species, y = body_mass_g)) +
geom_boxplot() +
theme_minimal() +
labs(x = "Species",
y = "Body mass (g)")
Or this adaptation of our initial plot with a line of best fit for the observed data by each species:
ggplot(penguins, aes(x= flipper_length_mm, y = body_mass_g, color = species)) +
geom_point() +
geom_smooth(method = "lm", se = F) +
theme_minimal() +
labs(x = "Length of the flipper",
y = "Body mass (g)",
color = "Species")
Now that you have been introduced to some of the basics of ggplot2
, the best way to move forward is to experiment. As we have discussed before, the R community is very open. Perhaps, you can gather some inspiration from the Tidy Tuesday social data project in R where users explore a new dataset each week and share their visualizations and code on Twitter under #TidyTuesday. You can explore some of the previous visualizations here and try to replicate their code.
Here is a curated list of awesome ggplot2
resources.
This week we learned that directed acyclic graphs (DAGs) are very useful to express our beliefs about relationships among variables.
DAGs are compatible with the potential outcomes framework. They give us a more convinient and intuitive way of laying out causal models. Next week we will learn how they can help us develop a modeling strategy.
Today, we will focus on their structure and some DAG basics with the ggdag
package.
To create our DAGs in R we will use the ggdag
packages.
The first thing we will need to do is to create a dagified object. That is an object where we state our variables and the relationships they have to each other. Once we have our dag object we just need to plot with the ggdag()
function.
Let's say we want to re-create this DAG:
We would like to express the following links:
To do so in R with ggdag
, we would use the following syntax:
dag_object <- ggdag::dagify(variable_being_pointed_at ~ variable_pointing,
variable_being_pointed_at ~ variable_pointing,
variable_being_pointed_at ~ variable_pointing)
After this we would just:
ggdag::ggdag(dag_object)
Let's plot this DAG
our_dag <- ggdag::dagify(d ~ p,
m ~ d,
y ~ d,
y ~ m)
ggdag::ggdag(our_dag)
EXERCISE:
See what happens when you add + theme_minimal()
, + theme_void()
, or + theme_dag() to the DAG. What package do you think is laying behind the mappings of
ggdag`?
our_dag <- ggdag::dagify(d ~ p,
m ~ d,
y ~ d,
y ~ m)
ggdag::ggdag(our_dag) +
theme_minimal()
ggdag::ggdag(our_dag) +
theme_void()
{{% /spoiler %}}
As you may have seen, the DAG is not rendered with the nodes in the positions we want.
If you ever want to explicitly tell ggdag
where to position each node, you can tell it in a Cartesian coordinate plane.
Let's take P as the point (0,0):
coord_dag <- list(
x = c(p = 0, d = 1, m = 2, y = 3),
y = c(p = 0, d = 0, m = 1, y = 0)
)
our_dag <- ggdag::dagify(d ~ p,
m ~ d,
y ~ d,
y ~ m,
coords = coord_dag)
ggdag::ggdag(our_dag) + theme_void()
Let's say we're looking at the relationship between smoking and cardiac arrest. We might assume that smoking causes changes in cholesterol, which causes cardiac arrest:
smoking_ca_dag <- ggdag::dagify(cardiacarrest ~ cholesterol,
cholesterol ~ smoking + weight,
smoking ~ unhealthy,
weight ~ unhealthy,
labels = c("cardiacarrest" = "Cardiac\n Arrest",
"smoking" = "Smoking",
"cholesterol" = "Cholesterol",
"unhealthy" = "Unhealthy\n Lifestyle",
"weight" = "Weight")
)
ggdag::ggdag(smoking_ca_dag, # the dag object we created
text = FALSE, # this means the original names won't be shown
use_labels = "label") + # instead use the new names
theme_void()
In this example, we:
coord_dag <- list(
x = c(d = 0, x = 1, y = 2),
y = c(d = 0, x = 1, y = 0)
)
our_dag <- ggdag::dagify(x ~ d,
y ~ d,
y ~ x,
coords = coord_dag)
ggdag::ggdag(our_dag) + theme_void()
EXERCISE:
Let's adapt the code to make X a confounder and a collider.
{{% spoiler text="Answer" %}}coord_dag <- list(
x = c(d = 0, x = 1, y = 2),
y = c(d = 0, x = 1, y = 0)
)
our_dag <- ggdag::dagify(d ~ x, #line from x to d
y ~ d, #line from d to y
y ~ x, #line from x to y
coords = coord_dag)
ggdag::ggdag(our_dag) + theme_void()
coord_dag <- list(
x = c(d = 0, x = 1, y = 2),
y = c(d = 0, x = 1, y = 0)
)
our_dag <- ggdag::dagify(x ~ d, #line from d to x
y ~ d, #line from d to y
x ~ y, #line from y to x
coords = coord_dag)
ggdag::ggdag(our_dag) + theme_void()
{{% /spoiler %}}


Stevenage interim boss Mark Sampson charged by FA over alleged racist remark
The remark was alleged to have been made during a conversation about transfer targets.
Stevenage caretaker manager Mark Sampson has been charged by the Football Association with making an allegedly racist comment.
The former England Women head coach, who took interim charge at the Hertfordshire club in September, is accused of making the remark about a player during a conversation about transfer targets.
A statement from the FA released on Wednesday read: “Mark Sampson has been charged with a breach of FA Rule E3.
“It is alleged that a comment made by the Stevenage FC caretaker manager breached FA Rule E3(1) as it was improper and/or abusive and/or insulting.
“It is further alleged that the comment also constitutes an ‘aggravated breach’, which is defined in FA Rule E3(2), as it referenced ethnic origin and/or colour and/or race and/or nationality.”
The FA said Sampson has until December 6 to respond to the charge.
Stevenage said in September that an internal investigation into the matter had found that there was no case for Sampson to answer.
The club said at the time that the allegation was reported to the FA by phone “by a former coach the day after he was told by Sampson that he no longer required his services at the club”.
“The claimant was offered the chance to make a formal complaint but declined this opportunity, instead choosing to call the FA.
“Nevertheless, CEO Alex Tunbridge acted immediately to interview and take statements from two individuals the claimant said were witnesses, as well as others that were present in the same meeting, but not mentioned by the claimant.”
Wallace added: “In each case the witnesses did not support the allegations. Given that overwhelming outcome and the circumstances of the allegation, the club concluded there was no case to answer.
“Perhaps now that the FA have the evidence, they will make it clear there is no case to answer.”
The 37-year-old Welshman was sacked as England Women head coach by the FA in September 2017 following allegations of “inappropriate and unacceptable behaviour” in his previous role as manager at Bristol Academy.
He had also been the focus of bullying and racism claims, first made by Eni Aluko and then Drew Spence.
The FA said the allegations were investigated and Sampson was cleared of any wrongdoing.
But Sampson, who reached a financial settlement with the FA over his dismissal in January this year, conceded he should have handled the claims differently, saying it would always be a “big regret” and apologising unreservedly to the two players.


| DOSE: |
5.0 mg |
smoked |
5-MeO-DMT |
(powder / crystals) |
So I sit in my chair. Take a hit. Lose all ability to control my self as I see everything start to break apart by each individual atom. I have music playing so that I can have some sort of connection with the real world. After 5 seconds, I find that it doesn't matter. Within 1 minute all I know is my breathing and a wonderful feeling all through my body. I try to focus on breathing, impossible.
Next thing I know, Iím on the ground, vomit bursts out my mouth as I reach for the toilet which seems miles away.   I end up feeling so shitty and I see that my legs are all beat up and scratched with blood on them. Donít know why, so I take a shower.
I sit there for about 10 minutes still waiting for the world to fully connect and become solid again. Once out of the shower I walk out side of my room and into the living room to see three friends staring wild eyed at me and I say, 'If I new I was going to just pass out, throw up and then want to kill my self, Iíd stick to herb.' Well it turns out...this is what happened (That is what I remember, I do not remember any of what is below, this is an account from my roommate and friends).
I took the hit, started to breathe real heavily. My roommate leaves my room, where two other male friends and a female where sitting waiting to find out how this drug was. Then, they hear me screaming from my room very excitedly and they hear banging and I am yelling at the top of my lungs 'I am free!!!!' and when my room mate comes back in, he sees everything in my room thrown around and I am on the ground spinning round and round hitting my body into everything imaginable. I have dents in my wall on the corner from my head.
My other two friends come and try to restrain me so that I do not hurt my self, I give them the look of death and my entire body is bright red and my eyes are bulging out of my sockets.  As they try to hold me down I try and pull away from them down a hall way in my room towards the bathroom, they are unable to hold me down, or restrain me. I supposedly have supper human strength... (They just didn't know Iíve been working out lol ;) I make it to my bathroom where I squeeze my self in between the toilet and the bathtub still screaming it seems, but this time I was yelling something about pairs.
Finally they where able to get me back in the hall way some how and the two friends left the room and the other original friend stayed until I was calm. Supposedly laying on my back tapping my toe to the music. At this point, I am guessing this where I came too and reached forward towards the toilet. I have no memory at all of any of this. Honestly. I don't recommend it. It was no fun because what good is all that happened if 'I' wasn't there to experience it or get anything from it. Also, I think I may have just been given way too much to smoke for my mind and body to handle.
  It was fun for the first 5 seconds, and then...I just don't recommend this crap. Plenty of better drugs out there. Good day.
Experience Reports are the writings and opinions of the individual authors who submit them.
Some of the activities described are dangerous and/or illegal and none are recommended by Erowid.


[§572-16] Rules and regulations. The director of health may make such rules and regulations as may be necessary or appropriate to carry out the provisions of this chapter. [L 1969, c 19, §3]