Skip to content

Instantly share code, notes, and snippets.

@kjgarza
kjgarza / myDetector.js
Created February 19, 2012 04:12
myDetector
exports.main = function() {
require("widget").Widget({
id: "widgetID1",
label: "My Mozilla Widget",
contentURL: "http://www.mozilla.org/favicon.ico",
onClick: function(event) {
var XMLHttpRequest = require("xhr");
var request = new XMLHttpRequest();
request.open("GET", "http://www.myexperiment.org/search.xml?query=goble", false);
@kjgarza
kjgarza / getPubInfo
Created July 22, 2012 12:22
get publisher information from google scholar searches
var publ = document.querySelectorAll(".gs_a");
var dl =[];
for(i=0; i<publ.length; i++) {
var n = (publ[i].innerHTML).split("-");
dl[i] = n[1];
}
var result = {}, max = 0, res;
for(var v in dl) {
result[dl[v]] = (result[dl[v]] || 0) + 1;
@kjgarza
kjgarza / getSearchTitles
Created July 22, 2012 15:29
Google scholar obtain all titles from search
var publ = document.querySelectorAll(".gs_rt");
var dl =[];
for(i=0; i<publ.length; i++) {
var n = publ[i].textContent;
dl[i] = n;
}
console.log(dl);
@kjgarza
kjgarza / gist:3691541
Created September 10, 2012 15:29
Statement plot in R
y1 <- read.csv(file="/Users/kristian/Documents/statementforR.csv",sep=",",head=TRUE)
#y2 <- y1[y1$item == 'LIDL UK MANCHESTER',]
y3 <- y1[grep("CASH", y1$item), ]
plot(as.Date(y1$date, format='%d/%m/%Y'),y1$debit,type="l", col="blue", xlab="Time", ylab="Debit", ylim=range(c(y1$debit,y2$debit)), xlim=range(c(as.Date(y1$date, format='%d/%m/%Y'),as.Date(y2$date, format='%d/%m/%Y'))))
@kjgarza
kjgarza / gist:3721296
Created September 14, 2012 10:58
myimpact
var json =
{
"max":196419,
"buckets":
[
{
"d":1346835600,
"i":
[
[
@kjgarza
kjgarza / authorRatio
Created October 3, 2012 17:25
Ration of Author to Cite himself
var auth = "Floridi"
var authors = document.querySelectorAll(".gs_a");
var c = 0;
for(i=0; i<authors.length; i++) {
var name = authors[i].innerHTML;
if (name.indexOf(auth) != -1){
c++;
}
}
@kjgarza
kjgarza / jqueryfy
Created October 10, 2012 15:06
jqueryfy
(function() {
var el=document.createElement('div'),
b=document.getElementsByTagName('body')[0],
otherlib=false,
msg='';
el.style.position='fixed';
el.style.height='32px';
el.style.width='220px';
@kjgarza
kjgarza / R replace
Created November 20, 2012 10:48
R replace
df <- data.frame(
coun)
profession.code <- c(`0` = 0, "1"="mexico", Accountants=2, Veterinarians=3,
`Financial analysts`=4, Nurses=5)
df$profession.str <- names(profession.code)[match(df$coun, profession.code)]
wordSearch<- "problem"
i<-1
files<-RQDAQuery("select file from source where status=1")
file<-files$file[i][1]
lines<- unlist(strsplit(file, "\n[ \t\n]*\n*"))
r<-grep(wordSearch, lines)
# load required libraries
require(maps)
require(RColorBrewer)
# Create a dataframe with the reported observations
# get data from https://www.cia.gov/library/publications/the-world-factbook/rankorder/rawdata_2228.txt
# transform it to csv
r <- read.csv(file=paste0("/Dropbox/Data/rawdata_2228.csv"),sep=",",head=FALSE)
loc<-r$V2
cases<-r$V3