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
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 / 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) {
@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)
@sudevschiz
sudevschiz / email_utility.py
Created January 29, 2016 07:39
This utility is to automatically mail a report to User once test-suite execution has been completed and the report is generated using SMTP (Outlook exchange). Code is customised for Selenium automation testing. The scraping location in the report has to be modified.
import smtplib
from os.path import basename
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.utils import COMMASPACE, formatdate
import sys
import datetime
import json