Skip to content

Instantly share code, notes, and snippets.

View sudevschiz's full-sized avatar
🎯
Focusing

Sudev sudevschiz

🎯
Focusing
  • Soon enough!
  • Tokyo, Japan
View GitHub Profile
@sudevschiz
sudevschiz / Code.gs
Last active January 29, 2016 06:50
findLatLong
function findLatLong() {
var sheet = SpreadsheetApp.getActiveSheet();
SpreadsheetApp.getUi().alert('Hello, world!');
var startRow = 2; // First row of data to process
var numRows = 2; // Number of rows to process
// Fetch the range of cells A2:B3
var dataRange = sheet.getRange(startRow, 2, numRows, 2)
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (i in data) {
function findLatLong() {
Logger.log(SpreadsheetApp.getActive());
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getDataRange();
var numRows = range.getNumRows();
var numCols = range.getNumColumns();
for (var i = 2; i <= numRows; i++) {
var locality = range.getCell(i,1).getValue();
@sudevschiz
sudevschiz / filehandling.sh
Created June 11, 2014 11:14
Renaming filename bash script
for file in *.jpg;
do
file ${file%*};
convert -crop 300x300+300+80 $file cropped/$file;
#do whatever you want. The filename is in the $file variable.
done
---
---
<!DOCTYPE html>
<html>
{% include head.html %}
<body itemscope itemtype="http://schema.org/Article">
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '364481490395389',
##If using for the first time, source the below packages
# source("https://bioconductor.org/biocLite.R")
# biocLite("org.Mm.eg.db")
##Load the db to the environment
library("org.Mm.eg.db")
## The list of EnsEMBL Gene IDs are stored in a file "ens.txt". Read the text file as a table
@sudevschiz
sudevschiz / distance_between_zipcodes.py
Created January 29, 2016 07:04
Python script to find distance between two zipcodes. May use Google or Bing APIs
import urllib2
import csv
import json
import time
#Output file
out_file = open('distance_output.csv','a')
i = 0
@sudevschiz
sudevschiz / convert_binary.py
Created January 29, 2016 07:10
Script to get binary values of number range. Useful to generate continuous truth table for many observations
import csv
#Specify start and end values in decimal
range_start = 1
range_stop = 2^15
with open('output_file.csv','w') as out_file:
@sudevschiz
sudevschiz / string_manipulation.py
Created January 29, 2016 07:13
Script to remove some unwanted character from a string. Basic string manipulation
out_file = open("out_file.txt","w")
with open('formulas.txt','r') as fil:
for lin in fil:
#Here, '+' is the unwanted character at the 0th position. Edit accordingly for other characters
if(lin[0] == "+"):
new_line = lin[1:]
print new_line
else:
@sudevschiz
sudevschiz / split_data.R
Created January 29, 2016 07:18
Snippet to split the data set into training and testing data sets
## Function to split the dataframe
## 143 is just a default seed
splitdf <- function(dataframe, seed=143,splitper) {
if (!is.null(seed)) set.seed(seed)
index <- 1:nrow(dataframe)
trainindex <- sample(index, (splitper/100)*trunc(length(index)))
trainset <- dataframe[trainindex, ]
testset <- dataframe[-trainindex, ]
list(trainset=trainset,testset=testset)
@sudevschiz
sudevschiz / sapply_eg.R
Created January 29, 2016 07:32
Example for sapply in R
## Supposed you want to apply an operation to every element in a vector. Efficient way to do it in R is to use sapply / lapply
## Sample vector of 100 observation
x_vec <- rnorm(100)
## Need to find the absolute value of each element
x_abs <- sapply(x_vec,abs)
## The above implementation equivalent to doing x_abs <- abs(x_vec)