Skip to content

Instantly share code, notes, and snippets.

View janeshdev's full-sized avatar

Janesh Devkota janeshdev

View GitHub Profile
@janeshdev
janeshdev / 0_reuse_code.js
Created February 19, 2014 00:06
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@janeshdev
janeshdev / velxy_velcomponent.R
Last active August 29, 2015 13:56
This function was created to convert the velocity with magnitude and direction from EFDC similar to x and y velocity components. #velocityxy #velocity
# A function to convert velocity xy EFDC file to velocity component file
velxy_convert <- function(file){
process_pp_template <- function(path) {
# Read data using quicktoolsr function
dat <- readts_EE(path)
# Reshape the data from long format to wide format
dat_mod <- dcast(dat, time ~ id)
return(dat_mod)
}
# Read the file
COUNTYFIPS NAME STATEPLANEFIPS EPSG
16079 Shoshone County 1103 26970
16073 Owyhee County 1103 26970
16071 Oneida County 1101 26968
16077 Power County 1101 26968
16075 Payette County 1103 26970
06115 Yuba County 0402 26942
06111 Ventura County 0405 26945
06113 Yolo County 0402 26942
31177 Washington County 2600 32104
@janeshdev
janeshdev / dateandtime.R
Last active December 15, 2015 00:19
Combine date and time into one variable with POSIXct class
jd1 <- read.csv("datetime.csv")
## Then a new variable called timestamp will be added to the dataframe jd1.
jd1 <- transform(jd1, timestamp=as.POSIXct(paste(Date,Time),format="%Y/%m/%d %H:%M"))
@janeshdev
janeshdev / regression.R
Last active December 18, 2015 11:19
Regression
# GET EQUATION AND R-SQUARED AS STRING
# SOURCE: http://goo.gl/K4yh
lm_eqn = function(df){
m = lm(y ~ x, df);
eq <- substitute(italic(y) == a + b %.% italic(x)*","~~italic(r)^2~"="~r2,
list(a = format(coef(m)[1], digits = 2),
b = format(coef(m)[2], digits = 2),
r2 = format(summary(m)$r.squared, digits = 3)))
as.character(as.expression(eq));
@janeshdev
janeshdev / insetgraphs.R
Created June 13, 2013 19:15
Create inset graphs in ggplot2
library(ggplot2)
library(grid)
# A viewport taking up a fraction of the plot area
vp <- viewport(width = 0.4, height = 0.4, x = 0.1, y = 0.9,just=c("left","top"))
b_plot <- ggplot(cars,aes(speed,dist))+geom_line()+xlim(10,15)
b_plot
## Let us assign a sample date as first with hours, minutes and seconds.
## It is also recommended to use the time zone
> date <- as.POSIXct("2013-06-14 16:34:26",tz="GMT")
## Convert to Julian date using the following function
> jddd <- julian(date, origin = as.POSIXct("2013-01-01 00:00:00",tz="GMT"))
> jddd
Time difference of 164.6906 days
@janeshdev
janeshdev / displayonebyone.tex
Created June 19, 2013 22:38
This gist shows how to display the items in beamer one by one using \only overlay
\documentclass{beamer}
\usetheme{CambridgeUS}
\setbeamertemplate{items}[ball]
\usefonttheme[onlylarge]{structurebold}
\usecolortheme[RGB={205,173,0}]{structure}
\setbeamerfont*{frametitle}{size=\normalsize,series=\bfseries}
\useoutertheme{infolines}
%Pacakges
\usepackage{xcolor}
@janeshdev
janeshdev / multiplot.R
Created June 23, 2013 19:36
It can take any number of plot objects as arguments, or if it can take a list of plot objects passed to plotlist.
# Multiple plot function
#
# ggplot objects can be passed in ..., or to plotlist (as a list of ggplot objects)
# - cols: Number of columns in layout
# - layout: A matrix specifying the layout. If present, 'cols' is ignored.
#
# If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE),
# then plot 1 will go in the upper left, 2 will go in the upper right, and
# 3 will go all the way across the bottom.
#
@janeshdev
janeshdev / index.html
Created February 11, 2016 21:34
Testing
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font: 10px sans-serif;
}
.axis path,
.axis line {