Skip to content

Instantly share code, notes, and snippets.

@ddbs
ddbs / Recipes - Entity Extraction.ipynb
Created May 1, 2019 20:01 — forked from psychemedia/Recipes - Entity Extraction.ipynb
Examples of tagging and fuzzy matchings items in txt docs using python
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ddbs
ddbs / metaprogramming.R
Created April 17, 2018 09:47 — forked from wjhopper/metaprogramming.R
Metaprogramming in R
# Create a function programmatically by creating its constituents:
# an argument list, a function body of expressions, and an enclosing environment
args <- alist(x=,y=)
exps <- expression(z <- x^2 + y^2, z <- sqrt(z), return(z))
body <- as.call(c(as.name("{"), exps))
f <- as.function(x = c(args,body), envir = parent.frame())
f(x=1,y=1)
@ddbs
ddbs / deployment-tool-ansible-puppet-chef-salt.md
Created March 4, 2017 10:29 — forked from jaceklaskowski/deployment-tool-ansible-puppet-chef-salt.md
Choosing a deployment tool - ansible vs puppet vs chef vs salt

Requirements

  • no upfront installation/agents on remote/slave machines - ssh should be enough
  • application components should use third-party software, e.g. HDFS, Spark's cluster, deployed separately
  • configuration templating
  • environment requires/asserts, i.e. we need a JVM in a given version before doing deployment
  • deployment process run from Jenkins

Solution

@ddbs
ddbs / Rperf.sh
Created January 2, 2017 15:45 — forked from mbacou/Rperf.sh
Benchmarking FastRWeb and OpenCPU
## Comparing execution times between OpenCPU (RApache) and FastRWeb (Rserve and HTTP).
## Same requests and same code. Note that FastRWeb is up to 13 times faster on the 2nd call.
# OpenCPU: summarize 2 layers across districts for the whole of SSA, return json of summary table
# and then json of all pixel values for mapping
$ time curl http://127.0.0.1/ocpu/library/hcapi3/R/getLayer/json \
-d '{"var" : ["whea_h", "AEZ16_CLAS"], "by" : "ADM2_NAME_ALT"}' -X POST -H "Content-Type:application/json"
[...]
{
@ddbs
ddbs / ipak.R
Created October 19, 2016 22:04 — forked from stevenworthington/ipak.R
Install and load multiple R packages at once
# ipak function: install and load multiple R packages.
# check to see if packages are installed. Install them if they are not, then load them into the R session.
ipak <- function(pkg){
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if (length(new.pkg))
install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}
@ddbs
ddbs / stratifiedCV.r
Created June 5, 2016 23:41 — forked from mrecos/stratifiedCV.r
Stratified K-folds Cross-Validation with Caret
require(caret)
#load some data
data(USArrests)
### Prepare Data (postive observations)
# add a column to be the strata. In this case it is states, it can be sites, or other locations
# the original data has 50 rows, so this adds a state label to 10 consecutive observations
USArrests$state <- c(rep(c("PA","MD","DE","NY","NJ"), each = 5))
# this replaces the existing rownames (states) with a simple numerical index
@ddbs
ddbs / 0_reuse_code.js
Created November 28, 2015 09:56
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
@ddbs
ddbs / .gitignore
Last active August 29, 2015 14:27 — forked from octocat/.gitignore
Some common .gitignore configurations
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
@ddbs
ddbs / functions.php
Last active August 29, 2015 14:01 — forked from claudiosanches/functions.php
WooCommerce: Hide price and add-to-cart button for non-logged in users.
//Hide price and add-to-cart button for non-logged in users.
function woocommerce_template_loop_price() {
if ( is_user_logged_in() )
woocommerce_get_template( 'loop/price.php' );
}
function woocommerce_template_loop_add_to_cart() {
if ( is_user_logged_in() )
woocommerce_get_template( 'loop/add-to-cart.php' );
<?php
/**
* Code goes in functions.php or a custom plugin.
*/
add_filter( 'woocommerce_states', 'malaysia_woocommerce_states' );
function malaysia_woocommerce_states( $states ) {
$states['MY'] = array(
'JHR' => __('Johor', 'woocommerce') ,