Skip to content

Instantly share code, notes, and snippets.

View vicapow's full-sized avatar

Victor vicapow

View GitHub Profile
@vicapow
vicapow / README.md
Last active April 5, 2023 12:45
getStyles function from NYT's Crowbar

Get all the styles as a string from a given document. useful for creating a PNG from an SVG. SVG's need to have all of their style information embedded within their document to be properly exported.

Example usage:

var styles = getStyles(window.document);

Try it by going to [http://bl.ocks.org/vicapow/raw/9904319/](this block) and running the above usage example in the console.

@vicapow
vicapow / Readme.md
Last active March 8, 2023 07:37
WebGL + d3.layout.force

This demo uses d3.layout.force() to calculate the node positions and then passes those to webGL to render them on the GPU.

@vicapow
vicapow / index.js
Last active December 15, 2021 21:56
requirebin sketch
var d3 = require('d3')
, _ = require('underscore')
, w = window.innerWidth
, h = window.innerHeight - 100
, tempo = 500
// , data = {
// 'Derek Jeter' : {
// '1995' : [12, 48]
// , '1996' : [183, 582]
// }
@vicapow
vicapow / geos-voronoi-in-js.c
Last active May 4, 2021 23:47
example of compiling geos to JS because why not
/*
To compile:
first, get a version of geos and put it in `geos` relative path. then...
cd geos
emconfigure ./configure
emmake make
cd ..
emcc \
-s EXPORTED_FUNCTIONS='["_get_voronoi"]' \
(async function() {
async function fetchData(date) {
var date_split = date.split('-'),
year = date_split[0],
month = date_split[1],
day = date_split[2];
if (parseInt(day) < 10){
day = parseInt(day);
}
month = parseInt(month) - 1;
@vicapow
vicapow / main.cpp
Created June 29, 2020 17:35
C++ rvalue reference and move semantics
#include <iostream>
#include <vector>
using namespace std;
struct A {
int * ptr;
A() {
cout << "Constructor" << endl;
ptr = new int;
@vicapow
vicapow / remove-lodash-es.js
Created March 6, 2020 21:46
convert lodash-es back to lodash
export default function transformer(file, api) {
const j = api.jscodeshift;
const root = j(file.source);
let body;
root.find(j.Program).map(program => {
body = program.value.body;
});
const lodashImports = root
@vicapow
vicapow / README.md
Last active December 17, 2019 11:15
An example of creating a PNG from an SVG in D3.

This is an example of creating a PNG from an SVG. (You should notice that you're able to right click on the last image and save it as a PNG image.) It has been Tested in Firefox and Chrome but doesn't work in Safari as of 2014-07-20.

Normally, you'll create your SVG in D3 but to make the example a bit more readable, the SVG is already placed in the document. There are a few important points. Namely:

  1. All the styles of the SVG need to be self contained in side of the <defs> tags. (These styles should be escaped using the <![[CDATA[ ... ]] tag.)
  2. The SVG needs to have the proper namespaces and document types.
  3. The SVG needs to be saved to an image, then read from an canvas element, then saved to an image again.

Note: Portions of this demo where taken from The New York Times' excellent Crowbar SVG extractor.

@vicapow
vicapow / styled-components_v4.x.x.js
Created February 12, 2019 04:03
styled-components_v4.x.x.js
// @flow
declare module 'styled-components' {
// { type: '__styled' } is really only used ot avoid type collisions
// betwteen the interpolation unions types of (props: P) => string | number)
// and StyledComponent<any>.
declare export type StyledComponent<Props> = { type: '__styled' } & React$ComponentType<Props>;
declare export type Interpolation<P> =
| StyledComponent<any> // Order seems to matter unexpectedly.
@vicapow
vicapow / d3_v3.x.x.x.js
Created February 8, 2019 22:16
A d3 v3 Flow libdef
// @flow
declare module 'd3' {
declare module.exports: $Exports<'d3-es6-module'>;
}
declare module 'd3-es6-module' {
/**
* The current version of D3.js.
*/