Skip to content

Instantly share code, notes, and snippets.

View Proteusiq's full-sized avatar

Prayson Wilfred Daniel Proteusiq

View GitHub Profile
#!/usr/bin/env python
import multiprocessing
import random
import time
class Logger:
def __init__(self, num_lines, last_output_per_process, terminal_lock):
self.num_lines = num_lines
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"""
@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
#
@simoncos
simoncos / miniconda_on_rpi.md
Last active August 9, 2023 07:18
Install Miniconda 3 on Raspberry Pi
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
"""
@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]
@bgusach
bgusach / multireplace.py
Last active February 16, 2024 02:52
Python string multireplacement
def multireplace(string, replacements, ignore_case=False):
"""
Given a string and a replacement map, it returns the replaced string.
:param str string: string to execute replacements on
:param dict replacements: replacement dictionary {value to find: value to replace}
:param bool ignore_case: whether the match should be case insensitive
:rtype: str
"""
@jesslilly
jesslilly / README.md
Last active March 22, 2024 14:16
Deluxe Cron Job Wrapper

Cron Job Wrapper Wish List

I want a script that will give me:

  1. Logging
  2. Log purging!
  3. Email errors!
  4. Prevent duplicate processes! (flock)
  5. Source an environment file!
  6. Anything else?
# 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()