Skip to content

Instantly share code, notes, and snippets.

.node {
cursor: pointer;
}
.node circle {
fill: #fff;
stroke: #f98415;
stroke-width: 1.5px;
}
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
@Dulani
Dulani / AWS-RHEL
Created September 18, 2014 05:30
Setup R and RStudio on RHEL on AWS
#Setup and launch an RHEL EC2 instance
#Ensure that the security group (firewall) allows access to port 8787
#Login via SSH
#Guide: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html
ssh -i keyfile.pem ec2-user@ec2-11-22-33-44.compute-1.amazonaws.com
#Keyfile.pem is the name of your the keyfile you generated with AWS.
#RHEL users are either root or ec2-user
#ec2-11-22-33-44.compute-1.amazonaws.com is the "actuall" public name assigned by AWS
@Dulani
Dulani / Reclaim space on a Mac sparse bundle
Last active January 5, 2021 20:52
Reclaim free space in a Mac OS X sparse disk image (sparseimage).
#Original source: http://forums.macrumors.com/showthread.php?t=789978
hdiutil compact /path/to/xxxxx.sparseimage
@Dulani
Dulani / tryCatch() in R
Last active August 29, 2015 14:08
R: A working example with tryCatch() that takes action on bad data and then throws a warning.
parsedXml <- tryCatch( ParseAlert(xmlParse(alert.xml)),
error = function(e){ warning(paste("Problem encountered parsing alert XML for:",curMsgID,continuing));
warning(geterrmessage());
data.frame(NA)
return(NA)
}
)
@Dulani
Dulani / register doParallel for dplyr and foreach
Created October 23, 2014 18:16
The parallel back end CPU registration code for doParallel/foreach/dplyr
require(dplyr)
require(parallel)
require(foreach)
require(doParallel)
cpuCount <- detectCores() #From the parallel package
registerDoParallel(cores=cpuCount-1) #Don't take all cores.
dplyr({put dplyr data arguments here},.parallel=T) #Run dplyr in parallel.
/**
* Retrieves all the rows in the active spreadsheet that contain data and logs the
* values for each row.
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet
*/
function readRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
@Dulani
Dulani / SPARQL Lat Lon
Last active August 29, 2015 14:09
SPARQL Query for Army Installation lat/lon
# A quick way to pull a lat/lon table off Wikipedia for "all" US Army bases.
# SPARQL: on http://dbpedia.org/sparql
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX : <http://dbpedia.org/resource/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
@Dulani
Dulani / gist:985c32f5b14e64e3c792
Last active August 29, 2015 14:09
Geocoding in R using Google's API
# Geocoding in R using Google's API
require(RCurl)
require(XML)
require(data.table)
require(dplyr)
ridbLocs <- data.table(read.delim(file = "Data/ridbLocations.tsv"))
setnames(ridbLocs,c("original","locationType","simplified1","gCode","simplified","lat","lon"))
#' Model formula from my Google Sheet:
@Dulani
Dulani / Fill Down
Created January 27, 2015 16:29
Excel style "fill down" in R using data.table
#An Excel style "fill down" for Data Table. (.SD is the Subset of Data for each 'by' group)
dataTable[,setId:=.SD[1,setId],by=setNum] #TAG:USEFUL (Excel style fill down)