Skip to content

Instantly share code, notes, and snippets.

View baditaflorin's full-sized avatar

Florin Badita-Nistor baditaflorin

View GitHub Profile
# -*- coding: utf-8 -*-
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, String, Integer, ForeignKey,Boolean,DateTime,BigInteger,create_engine
from sqlalchemy.orm import sessionmaker,join
from sqlalchemy import update
import datetime
import time
import medium_posts_scrapper_gist as m
Base = declarative_base()
engine = create_engine("postgresql://postgres:pass@localhost:5432/medium_scrape")
@baditaflorin
baditaflorin / lda.py
Created December 26, 2016 16:06 — forked from light44/lda.py
Latent Dirichlet Allocation using gensim
import nltk
import pandas as pd
import re
import pprint
import operator
import csv
import logging
from stop_words import get_stop_words
from collections import defaultdict
from gensim import corpora
select * from
(select
--Extract all info from post_stats
ps.*,
-- Calculate the percentage for num_loves,num_wows,num_hahas,num_sads,num_angries
(ps.num_loves*100)/nullif((ps.num_reactions - ps.num_likes),0) perc_loves,
(ps.num_wows*100)/nullif((ps.num_reactions - ps.num_likes),0) perc_wows,
(ps.num_hahas*100)/nullif((ps.num_reactions - ps.num_likes),0) perc_hahas,
(ps.num_sads*100)/nullif((ps.num_reactions - ps.num_likes),0) perc_sads,
(ps.num_angries*100)/nullif((ps.num_reactions - ps.num_likes),0) perc_angries,
#Source http://www.craigaddyman.com/python-queues-and-multi-threading/
# standard libraries
from datetime import datetime
import Queue
from threading import Thread
# third party libraries
from bs4 import BeautifulSoup
import requests
WITH calculate_diff AS (
SELECT
post_id,
num_shares,
data_scraped,
--max(data_scraped) maxdata,
lag(num_shares) over (partition BY post_id ORDER BY data_scraped) as diff_1h,
lag(num_shares,4) over (partition BY post_id ORDER BY data_scraped) as diff_4h,
lag(num_shares,24) over (partition BY post_id ORDER BY data_scraped) as diff_1_day
FROM post_stats)
/*
NYTimes API Radial Graph Maker
February, 2009
blprnt@blprnt.com
This is a simple interface to visualize the occurence of various words in the NYTimes database over time.
This particular version displays the results as a radial bar graph, like this:
http://www.flickr.com/photos/blprnt/3257552056/
@baditaflorin
baditaflorin / README.md
Created November 28, 2016 15:59 — forked from addyosmani/README.md
108 byte CSS Layout Debugger

CSS Layout Debugger

A tweet-sized debugger for visualizing your CSS layouts. Outlines every DOM element on your page a random (valid) CSS hex color.

One-line version to paste in your DevTools

Use $$ if your browser aliases it:

~ 108 byte version

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
x <- structure(c("2012-09-27 09:08:37", "2012-09-29 10:06:33", "2012-10-01 09:44:36","2012-10-04 14:37:05", "2012-10-15 13:18:21", "2012-10-17 17:33:46","2012-10-18 11:52:13", "2016-10-06 15:11:01", "2016-10-07 13:00:09","2016-10-07 12:20:57"), class = c("xts", "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC", format = "%Y-%m-%d %H:%M:%S", index = structure(c(1348704000,1348876800, 1349049600, 1349308800, 1350259200, 1350432000, 1350518400,1475712000, 1475798400, 1475798400), tzone = "UTC", tclass = "Date"), .Dim = c(10L,1L))
y <- structure(c("1961-08-04 10:00:00", "1971-01-01 11:00:00", "1978-01-01 11:00:00","1979-01-01 11:00:00", "1983-01-01 11:00:00", "1984-01-01 11:00:00","1985-01-01 11:00:00", "2016-10-07 20:28:24", "2016-10-07 18:27:54","2016-10-08 00:38:40"), class = c("xts", "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC", format = "%Y-%m-%d %H:%M:%S", index = structure(c(-265420800,31536000, 252460800, 283996800, 410227200, 441763200, 4733
name w_highway total_km lanes_km maxspeed_km ref_km surface_km width_km sidewalk_km
canada unclassified 377,649 304,400 134,195 2,789 317,040 166 1,723
canada residential 262,424 213,683 9,844 2,286 166,879 28 11,321
canada tertiary 221,622 200,622 13,024