Skip to content

Instantly share code, notes, and snippets.

View makmac213's full-sized avatar

Mark Allan B. Meriales makmac213

View GitHub Profile
@makmac213
makmac213 / group_week_numbers.py
Created September 13, 2024 10:58
Group week numbers into [group_by_count]
from datetime import date
def group_week_numbers(start_date, end_date, group_by_count):
"""Group week numbers into [group_by_count]"""
initial_weeknum = start_date.isocalendar()[1]
end_weeknum = end_date.isocalendar()[1]
# end year should be from the isocalendar
# example if you use date(2025, 12, 31) isocalendar will be
# 2025 and week 1
end_year = end_date.isocalendar()[0]
@makmac213
makmac213 / diktador.py
Created December 12, 2021 15:36
Auto-suggest next word
import re
from nltk import (
FreqDist,
ngrams,
word_tokenize
)
def tokenize_phrases(phrases):
ret = []
for phrase in phrases:
@makmac213
makmac213 / spellcheck.py
Created October 30, 2021 16:17
Spellcheck using NLTK
from nltk.corpus import words
def spellcheck(w):
if w in words.words():
return True
return False
@makmac213
makmac213 / haiku.py
Created May 2, 2021 02:11
Suggest words
from nltk import word_tokenize, ngrams, FreqDist
from nltk.corpus import cmudict
import string
f = open('poem.txt', 'r')
doc = f.readlines()
texts = ' '.join(doc)
texts = texts.replace('\n', ' ')
tokenized = word_tokenize(texts)
# homebrew
# https://brew.sh
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# git
$ brew install git
# pip
$ sudo easy_install pip
@makmac213
makmac213 / thon.py
Last active April 24, 2020 10:32
Lodi Petmalu
# wadpata alaws wamaga ):
VOWELS = ["a", "e", "i", "o", "u"]
ADD_S = ["n", "t", "w"]
def syllabicate(word):
# Yorme style syllabication
# TODO: Incomplete find other test cases
word = word.lower()
0x119E2c5b180D8d2Bee8c2Fca42E9f4443A4D6fB2
import json
import requests
from bottle import debug, request, route, run
GRAPH_URL = "https://graph.facebook.com/v2.6"
VERIFY_TOKEN = 'YOUR_VERIFY_TOKEN'
PAGE_TOKEN = 'YOUR_PAGE_TOKEN'
def send_to_messenger(ctx):
import json
import requests
from bottle import debug, request, route, run
def build_service_url(service_url, cid):
"""build the service url"""
service_url = '{0}/v3/conversations/{1}/activities/'.format(service_url, cid)
return service_url
@makmac213
makmac213 / hugotbot.py
Last active December 17, 2018 11:41
hugotbot.py
from nltk.chat.util import Chat, reflections
pairs = [
[
r"My name is (.*)",
['hello %1', '%1 mabuhay ka'],
],
[
r'hi',
['hello', 'kamusta', 'mabuhay',],