Skip to content

Instantly share code, notes, and snippets.


Omar ElTayeby otayeby

View GitHub Profile
View Making to_csv and read_csv consistent for pandas
# This works in MACs
# Dataframe can also be used in R
import pandas as pd
##reading a csv file
df = pd.read_csv("PATH WHERE YOUR FILE IS SAVED/filename.csv", encoding='utf-8',lineterminator = '\n',index_col=0)
##writing a csv file
df.to_csv("PATH WHERE YOU WANT TO SAVE YOUR FILE/filename.csv",quoting=csv.QUOTE_NONNUMERIC, date_format='%Y-%m-%d %H:%M:%S', encoding='utf-8',line_terminator = '\n')
wesslen / stm-labels-five-words.R
Created Feb 28, 2018
get five words for stm topics
View stm-labels-five-words.R
labels <- sageLabels(ctmFit, n = 5)
topicsNames <- sapply(1:30, function(x) paste0(labels$marginal$frex[x,], collapse = " + "))
wesslen / twitter-trolls.Rmd
Last active Mar 19, 2018
troll-tweets Rmd
View twitter-trolls.Rmd
title: "Analyzing Russian Trolls: Tidyverse & Text"
author: "Ryan Wesslen"
date: "2/21/2018"
output: html_document
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, warning = FALSE)
nornagon /
Created Jul 21, 2017
Smith-Waterman Python implementation
import numpy as np
def smith_waterman(a: str, b: str, alignment_score: float = 1, gap_cost: float = 1) -> float:
Compute the Smith-Waterman alignment score for two strings.
This implementation has a fixed gap cost (i.e. extending a gap is considered
free). In the terminology of the Wikipedia description, W_k = {c, c, c, ...}.
This implementation also has a fixed alignment score, awarded if the relevant
WittmannF /
Last active Apr 11, 2021
Visualization of SVM Kernels Linear, RBF, Poly and Sigmoid on Python (Adapted from:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
from sklearn.cross_validation import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.datasets import make_moons, make_circles, make_classification
from sklearn.svm import SVC
h = .02 # step size in the mesh

Useful Pandas Snippets

A personal diary of DataFrame munging over the years.

Data Types and Conversion

Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)

fideloper /
Created Jun 6, 2012
You should develop in a Virtual Machine

#You should do all your LAMP development in a Virtual Machine

##Here's Why:

Many of us develop on Macintoshes. There are many reasons for this, but one of them is that it's based on a Unix platform of some sort. This allows us to run common server software such as Apache, Ruby, Python and Nodejs on our Macs.

Our computers become powerful develoment machines similar to the servers our apps will eventually live on.

Sometime we start our computer only to find Apache won't start, or MySQL can't create a PID file, or we've updated to Mountain Lion and Apache needs to be reconfigured. Death!