Skip to content

Instantly share code, notes, and snippets.

View diogo-almeida's full-sized avatar

Diogo Almeida diogo-almeida

View GitHub Profile
@coleoguy
coleoguy / gist:10136883
Last active September 9, 2015 20:37
just a simple sliding window function
slideFunct <- function(data, window, step){
total <- length(data)
spots <- seq(from = 1, to = (total - window + 1), by = step)
result <- vector(length = length(spots))
for(i in 1:length(spots)){
result[i] <- mean(data[spots[i]:(spots[i] + window - 1)])
}
return(result)
}
@JoFrhwld
JoFrhwld / ling-plot.Rnw
Created April 14, 2012 20:49
A knitr source file for including linguistic notation as graphical elements in ggplot2
\documentclass{beamer}
\usetheme{Singapore}
\usepackage{tipa}
%% Make the r-code small
\ifdefined\knitrout
\renewenvironment{knitrout}{\begin{footnotesize}}{\end{footnotesize}}
\else
\fi
@dsparks
dsparks / flag_plot.R
Created October 21, 2012 15:30
Replicating / improving http://shaheeilyas.com/flags/
# Replicating / improving http://shaheeilyas.com/flags/
# Drawing a scatter plot of raster images
doInstall <- TRUE # Change to FALSE if you don't want packages installed.
toInstall <- c("png", "reshape", "ggplot2", "MASS")
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
# Go to https://www.gosquared.com/resources/2400-flags, download the ZIP,
# and put the 64 x 64 files into a directory of your choosing.
@johndharrison
johndharrison / server.R
Created October 21, 2013 22:30
R Shiny regression example
library(RJSONIO)
shinyServer(function(input, output, session) {
output$test <- renderUI({
noPoints <- as.integer(input$obs)
series <- toJSON(cbind(seq(88, 266, by = (266-88)%/%(noPoints-1)), 113))
tags$script(HTML(
paste0("$(document).ready(function () {
@alexbbrown
alexbbrown / d3widget.js
Last active October 18, 2016 20:58 — forked from anonymous/d3widget.js
Simple Shiny Example of Javascript Input and Output
<script src="http://d3js.org/d3.v3.js"></script>
<script type="text/javascript">
(function(){
// Probably not idiomatic javascript.
this.countValue=0;
updateView = function(message) {
var svg = d3.select(".d3io").select("svg")
@fractaledmind
fractaledmind / EXPORT ALL SKIM NOTES TO EVERNOTE WITH HYPERLINKS (Complete)
Last active January 9, 2017 01:36
REQUIRED PROGRAMS: - Skim (pdf viewer and annotator) - Evernote (cloud based note app) This script will (as the title suggests) export all of you Skim notes directly to Evernote with hyperlinks. It integrates the GENERATE TOP 3 NOTES WITH SYSTEM URL script that will put 3 notes at the top of the PDF with linking information. This means your PDF …
@fletch
fletch / 2num.pl
Created September 10, 2009 19:42
#!/opt/local/bin/perl
##
## Slightly more idiomatic and optimized Perl of 2num.pl from
## http://github.com/brendano/awkspeed/tree/master
##
use strict;
use warnings;
open( my $vocab_fh, '>', "vocab" ) or die "vocab: $!\n";
@MarkEdmondson1234
MarkEdmondson1234 / dygraph_plot.r
Last active May 31, 2017 08:53
An example of rendering a Dygraph plot in Shiny
## in server.r
output$null_plot <- renderDygraph({
## don't output anything unless you have the data ready
validate(
need(casualImpactData(), "Model Working")
)
## the data for the plot is in here
ci <- casualImpactData()$series
@benmarwick
benmarwick / ngrams.R
Created April 12, 2013 07:57
How to extract ngrams from a corpus with R's tm and RWeka packages. From http://tm.r-forge.r-project.org/faq.html
library("RWeka")
library("tm")
data("crude")
BigramTokenizer <- function(x) NGramTokenizer(x, Weka_control(min = 2, max = 2))
tdm <- TermDocumentMatrix(crude, control = list(tokenize = BigramTokenizer))
inspect(tdm[340:345,1:10])
@rasmusab
rasmusab / tensorflow_in_r_using_rpython.R
Last active April 25, 2018 02:35
An example of building a TensorFlow model from R using rPython
### An example of building a TensorFlow model from R using rPython ###
# For this script you need to
# 1. Have python 2.7 installed.
# 2. Install the rPython package in R.
# 3. Install Google's TensorFlow library as per these instructions:
# http://www.tensorflow.org/get_started/os_setup.md#binary_installation
### Here is how to setup and run a trivial TensorFlow model ###
# Load TensorFlow (I couldn't get this to work without setting sys.argv... )