Skip to content

Instantly share code, notes, and snippets.

@rrguntaka
rrguntaka / scrape_election_results_india_2023.js
Last active December 3, 2023 07:27
Scrape Live India Election results - MLA Elections
//https://results.eci.gov.in/
//https://results.eci.gov.in/AcResultGenDecNew2023/partywiseleadresult-742S29.htm
//Navigating to the candidate list, open developer tools window, adn paste the following snippet in Console
jQuery(".custom-table table tbody tr").map(function (params) {
return {
"Constituency": jQuery("td:nth-child(2)", this).text(),
"Name": jQuery("td:nth-child(3)", this).text(),
"Margin": Number(jQuery("td:nth-child(5)", this).text())
import datetime
dt = datetime.datetime(2018, 1, 22)
end = datetime.datetime(2018, 12, 31)
step = datetime.timedelta(days=14)
result = []
while dt < end:
result.append(dt.strftime('%d-%b-%Y'))
arr = [
['k','l','n','m','d'],
['x','m','b','c','d'],
['r','a','r','y','x'],
['y','i','o','o','d'],
['m','s','g','p','t']
]
arrLen = len(arr)
s = "maryis"
@rrguntaka
rrguntaka / gist:cd6bddc5ad36cc6f78dff2e3261e0ce5
Created December 15, 2017 07:05 — forked from sebsto/gist:19b99f1fa1f32cae5d00
Install Maven with Yum on Amazon Linux
sudo wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo
sudo sed -i s/\$releasever/6/g /etc/yum.repos.d/epel-apache-maven.repo
sudo yum install -y apache-maven
mvn --version
@rrguntaka
rrguntaka / meanVarianceFromYahooData.scala
Created March 21, 2013 03:00
Calculate Mean Return and Variance matrix from the csv files downloaded from Yahoo Finance. Download the historical quotes data and update the tickers variable. Currently this program is just looking at last 200 days (one year). That parameter should be changed if analyzing for a different time horizon
package com.test
import scala.io.Source
object meanVarianceFromYahooData {
val root = "/"
def readData(f: String): List[Double] = {
val iter = Source.fromFile(root + f + "csv").getLines().drop(1).map(_.split(","))
def getClose: List[Double] = (iter map (_.last.toDouble)) toList
@rrguntaka
rrguntaka / getQuotesYahoo.R
Created November 5, 2012 06:25
Get 2011 Yearly quotes using R tseries and zoo package
get.quotes.2011 <- function(symbol){
get.hist.quote(instrument=symbol, start="2011-01-01",
end="2011-12-31", quote="AdjClose", provider="yahoo",
origin="1970-01-01", compression="d", retclass="zoo")
}
spy <- get.quotes.2011('spy')
@rrguntaka
rrguntaka / StartEndWeek.java
Created October 13, 2012 19:52
Week Start and End Dates in Java
import java.util.Calendar;
import java.util.Date;
public class StartEndWeek {
private Calendar cal;
private int weekStart;
public StartEndWeek(Date date, int weekStart) {
this.weekStart = weekStart;
this.cal = Calendar.getInstance();
@rrguntaka
rrguntaka / get_score_assignment.js
Created October 13, 2012 03:20
Coursera Score listing
result = function(){
var a = function(v){ return v.parentNode.nextSibling.nextSibling.nextSibling.nextSibling.textContent}
arr = $("b:contains('Total Score')").map(function(k,v){return a(v)})
scores = $.map(arr, function(n, i){
strs = n.split(" / ")
return {score:Number(strs[0]),max:Number(strs[1])}
});
mt = 0;st = 0;$.each(scores, function(i,n){mt += n.max;st += n.score})
return "Max Points: " + mt + ", Correct: " + st + ", Overall Score: " + (st/mt*100.0).toFixed(2) + " %"}()
save(dt, file="file.RData")
load("file.RData")
[source](http://r.789695.n4.nabble.com/How-to-create-a-permanent-dataset-in-R-td924692.html)
@rrguntaka
rrguntaka / run_for_each_file
Created October 11, 2012 22:07
Run a system command for matched files
for fname in glob.glob('./*.jar'): os.system("echo " + fname)