Skip to content

Instantly share code, notes, and snippets.

@satomacoto
satomacoto / sample.py
Created May 12, 2019 23:48
copy django FileFiled object to tempfile
import shutil
import tempfile
from app.models import Record
# %%
%%time
with tempfile.NamedTemporaryFile() as tmp:
record = Record.objects.first()
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Viterbi algorithm
# http://en.wikipedia.org/wiki/Viterbi_algorithm
#
# > python viterbi.py
# 0 1 2
# Rainy: 0.06000 0.03840 0.01344
# Sunny: 0.24000 0.04320 0.00259
# (0.01344, ['Sunny', 'Rainy', 'Rainy'])
import base64
import cv2
from PIL import Image
cap = cv2.VideoCapture(0)
_, img = cap.read()
image_string = cv2.imencode(".png", img)[1].tostring()
output = io.BytesIO()
Image.fromarray(img).save(output, format='PNG')
@satomacoto
satomacoto / download_with_requests.py
Created April 21, 2019 22:58
download with requests
import shutil
import requests
def download(url, dst):
response = requests.get(url, stream=True)
with open(str(dst), 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
del response
@satomacoto
satomacoto / __README.md
Created March 17, 2019 22:23
How to add Slack incoming webhook
  1. https://api.slack.com/apps
  2. Create New App
  3. Set App Name and Development Slack Workspace
  4. Tap App to move Building Apps for Slack
  5. Add features and functionality
  6. Select Incoming Webhooks
  7. Add New Webhook to Workspace
@satomacoto
satomacoto / extract_youtube_videoid.py
Last active February 23, 2019 11:45
Extract youtube video id from html
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# extract YouTube videoids from html
import re
import json
import urllib2
from BeautifulSoup import BeautifulSoup
def get_videoids(url):
(function() {
var language_info = {
languages_top: [
{ code: "de", name: "Deutsch" },
{ code: "en", name: "English", checked: true },
{ code: "es", name: "español" },
{ code: "es-419", name: "español (Latinoamérica)" },
{ code: "fr", name: "français" },
{ code: "hr", name: "hrvatski" },
{ code: "it", name: "italiano" },
@satomacoto
satomacoto / setup.sh
Last active October 25, 2018 05:37
Install node and npm with n
# install node & npm
apt-get install -y nodejs npm apt-transport-https
npm cache clean
npm install n -g
n stable
ln -sf /usr/local/bin/node /usr/bin/node
ln -sf /usr/local/bin/npm /usr/bin/npm
import seaborn as sns
colorDict = {}
palette = "hls"
colorPalette = sns.color_palette(palette, len(allLabels))
for i, label in enumerate(allLabels):
colorDict[label] = colorPalette[i]
@satomacoto
satomacoto / gensim_vs_sklearn.py
Created August 18, 2015 08:18
gensim vs. sklearn
# -*- coding: utf-8 -*-
import gensim
from sklearn.feature_extraction.text import CountVectorizer
from gensim.corpora.dictionary import Dictionary
from gensim.corpora import MmCorpus
import numpy as np
import lda