Skip to content

Instantly share code, notes, and snippets.

View StevenJL's full-sized avatar

Steven Li StevenJL

  • Fountain Inc.
  • SF Bay Area
  • 00:26 (UTC -08:00)
View GitHub Profile
// 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]);}
);
// 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
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")
// 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])
/* 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
@StevenJL
StevenJL / headers.c
Last active March 19, 2017 06:10
sock_programming/headers
#include <stdio.h>
// for input output
#include <stdlib.h>
// general helper functions
#include <string.h>
// for manipulating arrays of characters
#include <unistd.h>
@StevenJL
StevenJL / connect.c
Last active March 19, 2017 08:54
sock_programming/connect
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);
}
@StevenJL
StevenJL / bind.c
Created March 20, 2017 05:08
sock_programming/bind
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));
@StevenJL
StevenJL / const.js
Last active March 22, 2017 02:17
ES6/constant
// `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";
@StevenJL
StevenJL / anonfunc.js
Created March 22, 2017 02:36
ES6/arrowfunc
// 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)
})