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 / list_creation_profiling.R
Created July 29, 2012 12:04
Four different ways of creating lists
f1 <- function (n) {
l <- list()
for(idx in 1:n) {
l <- append(l, idx)
}
return(l)
}
f2 <- function (n) {
l <- list()
@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-Ratings-in-notifications.patch
Created March 17, 2012 08:09
Rhythmbox patch for Ratings in notification.
From 8a07f968d5185e23ec089669b1d2e2c65ccdcf68 Mon Sep 17 00:00:00 2001
From: Utkarsh Upadhyay <musically.ut@gmail.com>
Date: Sat, 17 Mar 2012 13:14:45 +0530
Subject: [PATCH] Ratings in notifications.
1. Adds buttons to rate the playing entry from the song-change/status-icon notification itself.
2. Adds configuration UI to enable/disable the rating buttons.
---
data/org.gnome.rhythmbox.gschema.xml | 10 +
plugins/notification/Makefile.am | 6 +
@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 / cmd_list.txt
Created December 31, 2011 20:23
Command history
[21:15] utkarsh@Arrakis:~/prog$ history | awk '{print $2}' | sort | uniq -c | sort -rn
74 ./a.out
62 git
53 gcc
48 cd
44 cat
40 exit
35 ll
29 ls
18 man
@musically-ut
musically-ut / test_intersection.py
Created December 31, 2011 19:54
Testing line intersections.
def test_intersects():
line_1 = ((0, 0), (1, 1))
line_2 = ((2.5, 2.5), (1.5, 1.5)) # No intersection
assert not intersects(line_1, line_2)
line_1 = ((0, 0), (1, 1))
line_2 = ((0, 0.5), (1, 0.5)) # Intersects
assert intersects(line_1, line_2)
line_1 = ((0, 0), (1, 1))
@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:
@musically-ut
musically-ut / stddevcalc_test.cpp
Created December 20, 2011 16:01
Testing Standard Deviation calculation
int main() {
StdDevCalc c, c2;
StdDevCalcKnuth k, k2;
for(int i = 0; i < 100; i++) {
c.append(i); // Small values
k.append(i);
c2.append((double) i * 3e151); // Very very large values
k2.append((double) i * 3e151);
@musically-ut
musically-ut / KnuthStdDev.cpp
Created December 20, 2011 15:55
Knuth's numerically stable standard deviation calculation
class StdDevCalcKnuth {
private:
long long m_count;
double m_meanPrev, m_meanCurr, m_sPrev, m_sCurr, m_varianceCurr;
public:
StdDevCalcKnuth() {
m_count = 0;
}
@musically-ut
musically-ut / stddevcalc.cpp
Created December 20, 2011 15:50
Naive standard deviation calculation
class StdDevCalc {
private:
long long m_count;
double m_sum_sq, m_sum, m_var;
public:
StdDevCalc() {
m_sum_sq = m_sum = m_var = m_count = 0;
}
void append(double d) {