Skip to content

Instantly share code, notes, and snippets.

View dantonnoriega's full-sized avatar

Danton Noriega-Goodwin dantonnoriega

View GitHub Profile
@dantonnoriega
dantonnoriega / python_blocks_for_repl.py
Last active September 18, 2021 03:19
Using SublimeREPL, this allows one to transfer AND evaluate blocks of python code. The code automatically detect python blocks, executes them, and skips white space, comment blocks (""") and comment lines (# ...).
"""
DESCRIPTION:
Using SublimeREPL, this plugin allows one to easily transfer AND
evaluate blocks of python code. The code automatically detect python
blocks and executes only code lines, omitting empty space and comments.
One can skips space, comment blocks and comment lines by executing on
empty lines, comments etc.
REQUIRES:
working with only 2 groups in the window. the main group (group 0)
from pandas import Series, DataFrame
import pandas as pd
import numpy as np
# SET UP FILES -----------------------------------------------------------------------
## create a main directory link and a subpath to file
## NOTE: anything in quotes `" "` is a data type called a 'string'. You should
## ALWAYS make file paths into strings to avoid parsing errors.
main_dir = "/Users/dnoriega/GitHub/Duke_PUBPOL590/"
csv_file = "02_data_structures_and_importing_data/data/sample_data_clean.csv"
@dantonnoriega
dantonnoriega / html2docx.sh
Last active April 8, 2020 00:14
Bash script that uses Applescript to convert all html files within a directory to docx files. It also converts headings and normal fonts to "Calibri"; resizes images; and also centers, adds spacing, and padding to tables.
#!/usr/local/bin/bash
# Original Applescript by Andrew Heiss (https://gist.github.com/andrewheiss/5bb905b1cfb244ebab40)
# SCRIPT MUST BE IN SAME DIRECTORY AS HTML FILES
# use: ~$ zsh ./html2docx.sh
# OR ~$ bash ./html2docx.sh
echo
html2docx () {
echo "Converting $2.html to $2.docx..."
osascript <<EOD
set base_folder to "$1/"
@dantonnoriega
dantonnoriega / xtable2kable.R
Created March 27, 2016 15:40
Some functions which take xtable objects and print as kable objects, keeping track, extracting the caption automatically, and then using pandoc-tablenos for referencing.
assignCount <- function(obj, kind, new=FALSE) {
# fromi https://rmflight.github.io/posts/2012/10/papersinRmd.html
incCount <- function(inObj, useName) {
nObj <- length(inObj)
useNum <- max(inObj) + 1
inObj <- c(inObj, useNum)
names(inObj)[nObj + 1] <- useName
inObj
}
@dantonnoriega
dantonnoriega / scriv2md.rb
Last active April 14, 2016 18:14
A ruby script to convert a Scrivener project (.scriv) into a single Markdown (.md). NOTE: This is my first experience with Ruby. Don't ask me anything too complicated because I just took the code, inferred the needed pieces, trimmed the fat, and adjust until I got the result!
#!/usr/local/bin/ruby
# SOURCE: scrivwatch.rb by Brett Terpstra, 2011, https://gist.github.com/ttscoff/1676667
# REPURPOSED AND RENAMED BY: Danton Noriega, April 2016
# Instructions:
# 1. place 'scriv2md.rd' in same directory as .scriv project
# 2. give permissions to 'scriv2md.rd':
# chmod u+x ./scriv2md.rd
# 3. use!
# ./scriv2md.rd /path/to/document.scriv
@dantonnoriega
dantonnoriega / Default (OSX).sublime-keymap
Last active September 17, 2017 02:50
How to hijack Andrew Heiss' awesome "knitr" keybinds to work with "R-Box" Rmd syntax. Woot.
// Send current chunk to R
{
"keys": ["super+alt+enter"],
"command": "knitr_send_chunk",
"context": [
{ "operand": "text.tex.latex.knitr source.r.embedded.knitr, text.html.markdown.knitr source.r.embedded.knitr, text.html.markdown.rmarkdown source.r", "operator": "equal", "match_all":true, "key": "selector" }
]
},
// Move between chunks
library(gtfsr)
library(magrittr)
library(dplyr)
set_api_key('2ec1ae29-b8c2-4a03-b96e-126d585233f9') # input your API key here
chi_feeds <- get_feedlist() %>%
filter(grepl('chicago', loc_t, ignore.case=TRUE))
cta_url <- chi_feeds$url_d[8] # get the GTFS feed url for CTA
@dantonnoriega
dantonnoriega / send_magrittr_pipe.py
Last active July 20, 2016 16:20
A command to select and automatically send full magrittr pipe sequence in Sublime Text 3. REQUIRES SEND TEXT PLUS. The keybinds required to make this work can be found here: https://gist.github.com/ultinomics/0ca9c3a04a3ed6592f134313d3124cf3
import sublime, sublime_plugin
class SendMagrittrPipe(sublime_plugin.TextCommand):
def move_cursor(self, line_num):
"""move cursor to the left of line"""
v = self.view
v.sel().clear()
region = v.line(v.text_point(line_num, 0))
v.sel().add(region.begin())
@dantonnoriega
dantonnoriega / send_magrittr_pipe.sublime-keymap
Last active July 11, 2016 17:54
Necessary keymaps to make the sublime plugin `send_magrittr_pipe.py` work correctly. REQUIRES SEND TEXT PLUS. Find the sublime plugin here: https://gist.github.com/ultinomics/49e99cc5b905d96f15af25e07a14935b
[
// search forward and backwards for pipes
{
"keys": ["super+enter"], "command": "send_magrittr_pipe",
"context":
[
{ "key": "following_text", "operator": "regex_contains", "operand": "%<>%|<>%|%>%|>%|%", "match_all": false },
{ "key": "selector", "operator": "equal", "operand": "source.r" }
]
},
# highcharter example: creating "scatter columns" with medians
# goal: scatter plot mpg by cyl, highlight medians
library(highcharter)
library(dplyr)
library(tibble)
library(purrr)
# BUILD HC DATA ------------------------------------------------
# convert to tibble