Skip to content

Instantly share code, notes, and snippets.

View kzinmr's full-sized avatar

Kazuki Inamura kzinmr

  • Tokyo, Japan
  • 12:13 (UTC +09:00)
View GitHub Profile
@kzinmr
kzinmr / cluster_df.py
Last active September 10, 2024 10:05
from collections import defaultdict, Counter
from operator import add
from functools import reduce
import numpy as np
from sklearn.cluster import KMeans
def dict_of_list(keys, values):
assert(len(keys) == len(values))
from collections import defaultdict
from functools import reduce, partial
import numpy as np
from itertools import chain
def flatten(l):
return list(chain.from_iterable(l))
@kzinmr
kzinmr / pmi.py
Last active September 10, 2024 10:07
PMI calculation
"calculate PMI(A,B)=P(A,B)/P(A)P(B) for every token A and B in a window"
from itertools import tee, combinations
from collections import Counter
def count_bigram(sentence, window=5):
# ['A','B','C','D', 'E', 'F', 'G'], 4 ->
# [['A', 'B', 'C', 'D'],
# ['B', 'C', 'D', 'E'],
# ['C', 'D', 'E', 'F'],
@zedeus
zedeus / following.py
Created September 2, 2019 21:06
Fetch Twitter following list
import requests, re, sys
url = "https://mobile.twitter.com/{}/following"
cursor = ""
usernames = []
first = True
if len(sys.argv) < 2:
print("Usage: python followers.py <username>")
quit(1)
@ibraheem4
ibraheem4 / postgres-brew.md
Last active May 4, 2026 04:03
Installing Postgres via Brew (OSX)

Installing Postgres via Brew

Pre-Reqs

Brew Package Manager

In your command-line run the following commands:

  1. brew doctor
  2. brew update
@epcim
epcim / update-ca-certificates.md
Last active March 14, 2025 17:32
trusted certificates system update-ca-certificates

Adding trusted root certificates to the server

Mac OS X

sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ~/new-root-certificate.crt
sudo security delete-certificate -c "<name of existing certificate>"

Windows

certutil -addstore -f "ROOT" new-root-certificate.crt

@kylebgorman
kylebgorman / bktree.py
Created November 4, 2015 02:48
Burkhard-Keller trees
# Copyright (c) 2014-2015 Kyle Gorman <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
@robvanoostenrijk
robvanoostenrijk / Instructions.md
Last active October 29, 2024 16:44
Install Mac OS X 10.6 SDK on newer Xcode
@etienned
etienned / extractdocx.py
Last active November 21, 2022 13:56
Simple function to extract text from MS XML Word document (.docx) without any dependencies.
try:
from xml.etree.cElementTree import XML
except ImportError:
from xml.etree.ElementTree import XML
import zipfile
"""
Module that extract text from MS XML Word document (.docx).
(Inspired by python-docx <https://github.com/mikemaccana/python-docx>)
@naoyat
naoyat / pre.sed
Created September 10, 2013 15:26
前処理
# s|^■||g
# s| : | |g
s|《 .* 》||g
s|{ .* }||g
s|〔 .* 〕||g
s|[ .* ]||g
s|( .* )||g
s|〈 .* 〉||g
s|【 .* 】||g