Skip to content

Instantly share code, notes, and snippets.

View zkan's full-sized avatar
🐻
Stay Hungry. Stay Foolish.

Kan Ouivirach zkan

🐻
Stay Hungry. Stay Foolish.
View GitHub Profile
@zkan
zkan / create_backup.sh
Created January 3, 2020 02:20
Create backup for WordPress site (Pronto-specific)
#!/bin/bash
cp docker-compose.yml backup/
cp get-docker.sh backup/
cp uploads.ini backup/
rsync -av --delete www/ backup/www/
sudo rsync -av --delete /var/lib/docker/volumes/rocket_db_data/ backup/rocket_db_data/
@zkan
zkan / sentiment_analysis.py
Created February 28, 2019 12:26
Sentiment Analysis with Scikit-Learn
import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer
text = [
'Promptly answer to my request.',
'great turnaround time!',
'Fast response and great service!',
'As usual you took the request and completed in as few steps as possible and well done!',
'Very quick turnaround time and great communication. Thank you!',
def fibonacci():
current_value, next_value = 0, 1
while True:
yield current_value
current_value, next_value = next_value, current_value + next_value
result = fibonacci()
for _ in range(10000000000000):
print(next(result))
@zkan
zkan / feature_selection_techniques.py
Created February 22, 2019 01:29
Feature Selection Techniques
import pandas as pd
import seaborn as sns
titanic_df = pd.read_csv('http://biostat.mc.vanderbilt.edu/wiki/pub/Main/DataSets/titanic3.csv')
titanic_df.head()
sns.countplot(x=titanic_df.survived, hue=titanic_df.sex)
sns.countplot(x=titanic_df.survived, hue=titanic_df.embarked)
sns.boxplot(x=titanic_df.survived, y=titanic_df.age)
@zkan
zkan / kmeans.py
Last active February 1, 2019 10:36
K-Means clustering
import pandas as pd
from sklearn import cluster
data = {
'data': [2, 3, 4, 10, 12, 20, 30, 11, 25]
}
df = pd.DataFrame(data)
kmeans = cluster.KMeans(n_clusters=2)
@zkan
zkan / jinja2_file_less.py
Created January 27, 2019 13:16 — forked from wrunk/jinja2_file_less.py
python jinja2 examples
#!/usr/bin/env/python
#
# More of a reference of using jinaj2 without actual template files.
# This is great for a simple output transformation to standard out.
#
# Of course you will need to "sudo pip install jinja2" first!
#
# I like to refer to the following to remember how to use jinja2 :)
# http://jinja.pocoo.org/docs/templates/
#
@zkan
zkan / test_fizzbuzz.py
Created December 16, 2018 01:58
FizzBuzz test using Pytest with external plugin loading: conftest.py
import pytest
@pytest.mark.parametrize('test_input, expected', [
(3, 'Fizz'),
  (6, 'Fizz'),
  (5, 'Buzz'),
  (10, 'Buzz'),
  (15, 'FizzBuzz'),
  (30, 'FizzBuzz'),
@zkan
zkan / conftest.py
Created December 16, 2018 01:56
FizzBuzz test using Pytest with external plugin loading: conftest.py
import pytest
class FizzBuzz:
def say(self, number):
if number % 3 == 0 and number % 5 == 0:
  return 'FizzBuzz'
  elif number % 3 == 0:
  return 'Fizz'
  elif number % 5 == 0:
@zkan
zkan / test_fizzbuzz.py
Created December 16, 2018 01:50
FizzBuzz test using Pytest with fixtures and test parametrization
import pytest
class FizzBuzz:
def say(self, number):
if number % 3 == 0 and number % 5 == 0:
  return 'FizzBuzz'
  elif number % 3 == 0:
  return 'Fizz'
  elif number % 5 == 0:
@zkan
zkan / test_fizzbuzz.py
Last active December 16, 2018 01:49
FizzBuzz test using Pytest with fixtures
import pytest
class FizzBuzz:
def say(self, number):
  if number % 3 == 0 and number % 5 == 0:
  return 'FizzBuzz'
  elif number % 3 == 0:
  return 'Fizz'
  elif number % 5 == 0: