Skip to content

Instantly share code, notes, and snippets.

View Proteusiq's full-sized avatar

Prayson Wilfred Daniel Proteusiq

View GitHub Profile
@benrules2
benrules2 / Markov.py
Created January 5, 2017 23:35
Markov Chain message generator
import random
import sys
def build_chain(text, chain = {}):
words = text.split(' ')
index = 1
for word in words[index:]:
key = words[index - 1]
if key in chain:
chain[key].append(word)
from sklearn.feature_extraction.text import TfidfVectorizer, CountVectorizer
from sklearn.decomposition import NMF, LatentDirichletAllocation
import numpy as np
def display_topics(H, W, feature_names, documents, no_top_words, no_top_documents):
for topic_idx, topic in enumerate(H):
print "Topic %d:" % (topic_idx)
print " ".join([feature_names[i]
for i in topic.argsort()[:-no_top_words - 1:-1]])
top_doc_indices = np.argsort( W[:,topic_idx] )[::-1][0:no_top_documents]
from gensim.models import KeyedVectors
# Load gensim word2vec
w2v_path = '<Gensim File Path>'
w2v = KeyedVectors.load_word2vec_format(w2v_path)
import io
# Vector file, `\t` seperated the vectors and `\n` seperate the words
"""
# CoffeeScript version of Google Spreadsheet Driver for Tableau Data Web Connector
init = ->
if !tableau
alert 'init- tableau NOT defined!'
return
tableau.scriptVersion = '1.0'
tableau.log 'init'
tableau.initCallback()
@rainabba
rainabba / config-docker.sh
Last active September 6, 2022 03:46
Install docker-ce, docker-compose and docker-sync in Ubuntu for WSL
#!/bin/bash
#
#This script assumes very little other than a fresh Ubuntu install (using the Windows store) on Win10 1709 or newer with WSL installed already
#In Powershell, run the following to install WSL and Ubuntu
#
#Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
#Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1604 -OutFile ~/Ubuntu.zip -UseBasicParsing
#Expand-Archive ~/Ubuntu.zip ~/Ubuntu
#~/Ubuntu/ubuntu.exe
#
from collections import OrderedDict
import numpy as np
import spacy
from spacy.lang.en.stop_words import STOP_WORDS
nlp = spacy.load('en_core_web_sm')
class TextRank4Keyword():
"""Extract keywords from text"""
@ameyavilankar
ameyavilankar / preprocess.py
Last active January 25, 2023 10:19
Removing Punctuation and Stop Words nltk
import string
import nltk
from nltk.tokenize import RegexpTokenizer
from nltk.corpus import stopwords
import re
def preprocess(sentence):
sentence = sentence.lower()
tokenizer = RegexpTokenizer(r'\w+')
tokens = tokenizer.tokenize(sentence)
@meganehouser
meganehouser / process3dGraph.py
Created February 6, 2012 13:24
This is a script which draws the amount of CPU used and memory usage of a process to a 3D graph.
#coding:utf-8
import psutil
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
TIME_NUM = 90
FRAMES = 360
@simoncos
simoncos / miniconda_on_rpi.md
Last active August 9, 2023 07:18
Install Miniconda 3 on Raspberry Pi
@evanscottgray
evanscottgray / docker_kill.sh
Last active November 7, 2023 03:40
kill all docker containers at once...
docker ps | awk {' print $1 '} | tail -n+2 > tmp.txt; for line in $(cat tmp.txt); do docker kill $line; done; rm tmp.txt