Skip to content

Instantly share code, notes, and snippets.

View thirdwing's full-sized avatar
🏠
Working from home

Qiang Kou (KK) thirdwing

🏠
Working from home
View GitHub Profile
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
void r_message(std::string text)
{
Rcpp::Function msg("message");
msg(text);
}
function writeStuff(n)
f=open("data.txt","w")
for el in 1:n
r=randi(Int32)
println(f,r)
end
close(f)
end
N = 1000_000
@romainfrancois
romainfrancois / gist:6119995
Created July 31, 2013 07:20
Two workarounds to get access to the c level connections api from c++.
#include <Rcpp.h>
// thanks to Simon for the macro magic
// problem #1: R internals uses "private" and "class" as
// member names. So a C++ compiler is confused
// when we include Connections.h
// this workaround uses the preprocessor to rename
// class as class_name and private as private_ptr
#define class class_name
#define private private_ptr
@tc
tc / gist:1217766
Created September 14, 2011 20:57
resize and crop using imagej -java version
package imagej;
import ij.*;
import ij.io.*;
import ij.process.*;
import java.io.*;
import javax.imageio.*;
import javax.imageio.stream.*;
import java.awt.image.BufferedImage;
@sbodenstein
sbodenstein / rnn_test.lua
Created July 27, 2016 23:11
Compare Torch + MXNet cuDNN RNN API's
--
require 'cudnn'
require 'cunn'
torch.setdefaulttensortype('torch.FloatTensor')
-- Get weight dim
function checkSums(rnn, seqLength, batch, inputDim, hiddenSize, layerNum, bidirectional)
rnn:reset()
@pssguy
pssguy / global.R
Last active January 21, 2018 01:25
Motion Chart of Premier League Positions by game for past 20+ seasons. Shiny app using googleVis package The data is not currently provided but to-date charts can be viewed at glimmer.rstudio.com/pssguy/eplTableMotion/
# load requisite libraries
library(shiny)
library(googleVis)
# load raw data (NB not provided)
tableByGame <- read.csv("../tableByGame.csv",stringsAsFactors=FALSE)
# to create chart need to repeat one column and get negative of league position as hack
tableByGame$game <- tableByGame$seasonGame
tableByGame$lgPos <- -tableByGame$lgPos
@smc77
smc77 / logistic_gradient_descent.R
Created October 28, 2011 03:14
Logistic Regression with Gradient Descent
num.iterations <- 1000
# Download South African heart disease data
sa.heart <- read.table("http://www-stat.stanford.edu/~tibs/ElemStatLearn/datasets/SAheart.data", sep=",",head=T,row.names=1)
x <- sa.heart[,c("age", "ldl")]
y <- sa.heart$chd
plot(x, pch=21, bg=c("red","green")[factor(y)])
# Function to standardize input values
@jcheng5
jcheng5 / server.R
Last active June 17, 2021 18:37
Shiny example: Diamonds Explorer
library(shiny)
library(ggplot2)
function(input, output) {
dataset <- reactive({
diamonds[sample(nrow(diamonds), input$sampleSize),]
})
output$plot <- renderPlot({
@brendano
brendano / gist:39760
Created December 24, 2008 20:11
load the MNIST data set in R
# Load the MNIST digit recognition dataset into R
# http://yann.lecun.com/exdb/mnist/
# assume you have all 4 files and gunzip'd them
# creates train$n, train$x, train$y and test$n, test$x, test$y
# e.g. train$x is a 60000 x 784 matrix, each row is one digit (28x28)
# call: show_digit(train$x[5,]) to see a digit.
# brendan o'connor - gist.github.com/39760 - anyall.org
load_mnist <- function() {
load_image_file <- function(filename) {
@BenLangmead
BenLangmead / DeBruijn.py
Last active September 26, 2023 15:39
Demonstration of de Bruijn graph construction and Eulerian path/cycle finding.
class DeBruijnGraph:
""" A de Bruijn multigraph built from a collection of strings.
User supplies strings and k-mer length k. Nodes of the de
Bruijn graph are k-1-mers and edges correspond to the k-mer
that joins a left k-1-mer to a right k-1-mer. """
@staticmethod
def chop(st, k):
""" Chop a string up into k mers of given length """
for i in xrange(0, len(st)-(k-1)):