This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // You can use `transition` to change elements | |
| // and `duration` to perform the transition over a period of time. | |
| d3.selectAll("g.overallG") | |
| .select("circle") | |
| .transition() | |
| .duration(1000) | |
| .attr("r", | |
| function(p) { return radiusScale(d[datapoint]);} | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // LOADING CSV Data | |
| // world_cup_data.csv | |
| "team","region","win","loss","draw","points","gf","ga","cs","yc","rc" | |
| "Netherlands","UEFA",6,0,1,18,12,6,2,23,1 | |
| "Spain","UEFA",6,0,1,18,8,2,5,8,0 | |
| "Germany","UEFA",5,0,2,15,16,5,3,10,1 | |
| "Argentina","CONMEBOL",4,0,1,12,10,6,2,8,0 | |
| "Uruguay","CONMEBOL",3,2,2,11,11,8,3,13,2 | |
| "Brazil","CONMEBOL",3,1,1,10,9,4,2,9,2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| d3.select("svg") | |
| .selectAll("rect") | |
| .data([15, 50, 22, 8, 100, 10]) | |
| .enter() | |
| .append("rect") | |
| .attr("width", 10) | |
| .attr("height", function(d) {return d;}) | |
| .style("fill", "blue") | |
| .style("stroke", "red") | |
| .style("stroke-width", "1px") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Casting | |
| parseInt("77"); | |
| parseFloat("3.14159"); | |
| Date.parse("Sun, 22 Dec 2013 08:00:00 GMT"); | |
| "alpha,beta,gamma".split(","); | |
| // Scaling | |
| var conv = d3.scale | |
| .linear() | |
| .domain([500000,13000000]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Include these headers to start playing with c network functions */ | |
| #include <sys/socket.h> /* /usr/include/sys/socket.h on Mac OS */ | |
| #include <netinet/in.h> /* /usr/include/netinet/in.h on Mac OS */ | |
| #include <arpa/inet.h> /* /usr/include/arpa/inet.h on Mac OS */ | |
| // CREATING SOCKETS | |
| int socket(int domain, int type, int protocol) | |
| /* | |
| Creates a new user socket, returns a file descriptor for socket or -1 | |
| if it errors. This is defined in sys/socket.h |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| // for input output | |
| #include <stdlib.h> | |
| // general helper functions | |
| #include <string.h> | |
| // for manipulating arrays of characters | |
| #include <unistd.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int tcp_sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); | |
| // AF_INET to create a IPv4 socket | |
| // SOCK_STREAM to use a stream-based protocol | |
| // IPPROTO_TCP to use the TCP protocol | |
| // if tcp_sock is -1, the socket failed to create | |
| if (tcp_sock < 0) { | |
| fputs("socket creation failed", stderr); | |
| exit(1); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int tcp_sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); | |
| // AF_INET to create a IPv4 socket | |
| // SOCK_STREAM to use a stream-based protocol | |
| // IPPROTO_TCP to use the TCP protocol | |
| // we create a struct to store ip address data; | |
| struct sockaddr_in address_info; | |
| // zero out the data in the struct | |
| memset(&address_info, 0, sizeof(address_info)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // `const` creates an 'immutable variable', that is a variables which cannot be | |
| // re-assigned new content. Note this only makes the variable itself immutable, | |
| // not its assigned content (for instance, in case the content is an object, | |
| // this means the object itself can still be altered). | |
| const PI = 3.14159; | |
| // `let` creates a variable that is scoped to its nearest containing block. | |
| // Compare this to `var` which scopes a variable to its nearest containing | |
| // function. | |
| let name = "Steve"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Use the arrow notation to create anonymous functions | |
| [1 , 3, 4, 5].map(v => v + 1) | |
| evens = [] | |
| [1, 2, 3, 4, 5].forEach(v => { | |
| if (v % 2 == 0) | |
| evens.push(v) | |
| }) |