Skip to content

Instantly share code, notes, and snippets.

View musically-ut's full-sized avatar
🐙
🐢 🎣 🐠

Utkarsh Upadhyay musically-ut

🐙
🐢 🎣 🐠
View GitHub Profile
@musically-ut
musically-ut / README.md
Last active December 28, 2015 12:49 — forked from mbostock/.block

This examples demonstrates how to use D3's brush component to implement focus + context zooming. Click and drag in the small chart below to pan or zoom.

@musically-ut
musically-ut / pointInArc.js
Created November 7, 2013 22:35
Function to figure out whether a point lies inside an arc
function pointIsInArc(pt, ptData, d3Arc) {
// Center of the arc is assumed to be 0,0
// (pt.x, pt.y) are assumed to be relative to the center
var r1 = arc.innerRadius()(ptData), // Note: Using the innerRadius
r2 = arc.outerRadius()(ptData),
theta1 = arc.startAngle()(ptData),
theta2 = arc.endAngle()(ptData);
var dist = pt.x * pt.x + pt.y * pt.y,
angle = Math.atan2(pt.x, -pt.y); // Note: different coordinate system.
@musically-ut
musically-ut / arePointsInsideWedge.js
Created November 7, 2013 22:39
Do all four corners lie inside a wedge?
g.append("text")
.attr("transform", function(d) { return "translate(" + arc.centroid(d) + ")"; })
.attr("dy", ".35em")
.style("text-anchor", "middle")
.text(function(d) { return d.data.age; })
.each(function (d) {
var bb = this.getBBox(),
center = arc.centroid(d);
var topLeft = {
@musically-ut
musically-ut / README.md
Last active December 15, 2015 14:59
The circle-text plugin.

A demo for the circle-text plugin, which can place text aligned along the bottom of circles.

@musically-ut
musically-ut / README.md
Last active December 12, 2015 08:59 — forked from mbostock/.block
Interacting with elements on brushes

This examples demonstrates how to use D3's brush component to implement focus + context zooming. Click and drag in the small chart below to pan or zoom.

@musically-ut
musically-ut / README.md
Last active December 12, 2015 08:49 — forked from mbostock/.block

This is an adaption of a Zoomable sunburst example with an added text box showing which item was last clicked.


Click on any arc to zoom in. Click on the center circle to zoom out.

A sunburst is similar to a treemap, except it uses a radial layout. The root node of the tree is at the center, with leaves on the circumference. The area (or angle, depending on implementation) of each arc corresponds to its value. Sunburst design by John Stasko. Data courtesy Jeff Heer.

@musically-ut
musically-ut / README.md
Last active November 2, 2015 10:50
Scripts to convert sqlite

Scripts to convert datasets from unruly forms to SQLite

The script json2sqlite.py reads files which have one JSON block per new line to be inserted in a database. This has become a rather common dataformat which is easy to incrementally parse. The arguments to the scripts are self explanatory.

Example execution: python json2sqlite.py --gzip aggressive_dedup.json.gz amazon.sqlite reviews

For a more upto date scripts, see: Networks-Leraning/datasets2sqlite.

@musically-ut
musically-ut / gist:3195033
Created July 28, 2012 22:37
Setting colors for my R-console.
# Copy this to your .Rprofile
library('colorout')
setOutputColors256(
normal = 40,
number = 214,
string = 85,
const = 35,
stderror = 45,
error = c(1, 0, 1),
warn = c(1, 0, 100)
@musically-ut
musically-ut / 0001-Notification-rating-plugin.patch
Created March 5, 2012 15:33
Rhythmbox patch for Ratings in notification.
From 15b12ffc5b4b22ab104cf796e7173db4eeaefe90 Mon Sep 17 00:00:00 2001
From: Utkarsh Upadhyay <musically.ut@gmail.com>
Date: Fri, 2 Mar 2012 11:56:32 +0530
Subject: [PATCH] Notification rating plugin.
---
data/org.gnome.rhythmbox.gschema.xml | 10 +
plugins/notification/Makefile.am | 6 +
plugins/notification/notification-preferences.ui | 28 +++
plugins/notification/rb-notification-plugin.c | 243 ++++++++++++++++++++-
@musically-ut
musically-ut / intersection.py
Created December 31, 2011 19:53
Line segment intersection
def intersects(line_1, line_2):
"""Whether line_1 and line_2 intersect or not."""
A, B = line_1
C, D = line_2
if _ccw(A,C,D) != _ccw(B,C,D) and _ccw(A,B,C) != _ccw(A,B,D):
# If the triangle pairs ACD, BCD and ABC, ABD have different
# orientations, then the segments have to intersect
return True
for pt in line_2: