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 / pretty_json.py
Created September 30, 2016 00:06 — forked from narate/pretty_json.py
Pretty print JSON from stdin. Code base from @aborigines [https://github.com/aborigines]. Base on this story on facebook -> https://www.facebook.com/koonnarate/posts/10202501031914513
#!/usr/bin/python
import sys
import json
data = sys.stdin.read()
json_data = json.loads("".join(data))
json_string = json.dumps(json_data, sort_keys=True, indent=4, ensure_ascii=False)
print(json_string)
@zkan
zkan / 11478266580.txt
Created November 4, 2016 13:36
Mejelly Test
เนื้อหาอยู่ที่นี่ เย้
@zkan
zkan / SNSTopic.py
Created February 16, 2017 23:51 — forked from stuartmyles/SNSTopic.py
A complete example of how to use Amazon Web Services Simple Notification Services from Python. This code uses the boto library https://github.com/boto/boto to create a topic, wait for a confirmation and then send a success message. Simply plug in your AWS access and secret keys, plus your email and mobile phone number.
# An example of how to use AWS SNS with Python's boto
# By Stuart Myles @smyles
# http://aws.amazon.com/sns/
# https://github.com/boto/boto
#
# Inspired by parts of the Ruby SWF SNS tutorial http://docs.aws.amazon.com/amazonswf/latest/developerguide/swf-sns-tutorial-implementing-activities-poller.html
# And the Python SNS code in http://blog.coredumped.org/2010/04/amazon-announces-simple-notification.html and http://awsadvent.tumblr.com/post/37531769345/simple-notification-service-sns
import boto.sns as sns
import json
@zkan
zkan / wilson.py
Created July 16, 2017 14:55
Lower bound of Wilson score confidence interval (3 rating scale)
"""
How Not To Sort By Average Rating:
http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
Note: Lower bound of a 95% confidence interval
"""
import math
import unittest
@zkan
zkan / download_anonymous_icons_from_drive.rb
Created August 1, 2017 00:11 — forked from rockwotj/download_anonymous_icons_from_drive.rb
Downloads all of the icons of anonymous animals from Google Drive
#!/usr/bin/env ruby
icon_list = "alligator, anteater, armadillo, auroch, axolotl, badger, bat, beaver, buffalo, camel, chameleon, cheetah, chipmunk, chinchilla, chupacabra, cormorant, coyote, crow, dingo, dinosaur, dolphin, duck, elephant, ferret, fox, frog, giraffe, gopher, grizzly, hedgehog, hippo, hyena, jackal, ibex, ifrit, iguana, koala, kraken, lemur, leopard, liger, llama, manatee, mink, monkey, narwhal, nyan cat, orangutan, otter, panda, penguin, platypus, python, pumpkin, quagga, rabbit, raccoon, rhino, sheep, shrew, skunk, slow loris, squirrel, turtle, walrus, wolf, wolverine, wombat"
for icon in icon_list.split ', ' do
element = icon.sub ' ', ''
`curl https://ssl.gstatic.com/docs/common/profile/#{element}_lg.png -o icons/#{element}.png`
end
@zkan
zkan / config.ru
Created August 1, 2017 02:23
HTTP Basic Authentication for Jekyll on Heroku
require 'rack/jekyll'
require "rack/rewrite"
use Rack::Auth::Basic, "Restricted Area" do |username, password|
[username, password] == ['admin', 'admin'] or [username, password] == ['zkan', '123'] or [username, password] == ['cory', 'cool']
end
use Rack::Rewrite do
rewrite %r{/(.+)}, lambda { |match, rack_env|
if File.exists?('_site/' + match[1] + '.html')
@zkan
zkan / woocommerce-cart-count-shortcode.php
Created September 28, 2017 07:04
WooCommerce Cart Count Shortcode (quick patch) for "PHP error Call to a member function get_cart_contents_count()"
<?php
/*
* Plugin Name: WooCommerce Cart Count Shortcode
* Plugin URI: https://github.com/prontotools/woocommerce-cart-count-shortcode
* Description: Display a link to your shopping cart with the item count anywhere on your site with a customizable shortcode.
* Version: 1.0.4
* Author: Pronto Tools
* Author URI: http://www.prontotools.io
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
import csv
from faker import Faker
fake = Faker()
with open('transactions.csv', 'r') as file_:
with open('anonymized_transactions.csv', 'w') as new_file:
reader = csv.DictReader(file_)
writer = csv.DictWriter(new_file, fieldnames=reader.fieldnames)

Effective Engineer - Notes

What's an Effective Engineer?

  • They are the people who get things done. Effective Engineers produce results.

Adopt the Right Mindsets

@zkan
zkan / try_mock_using_decorator.py
Last active January 5, 2018 17:07
Try Mock using Decorator
import random
import unittest
from unittest.mock import patch
class TryMockUsingDecoratorTest(unittest.TestCase):
@patch('__main__.random.randrange')
@patch('__main__.random.randint')
def test_mock_random_twice(self, mock_randint, mock_randrange):
try_mock_using_decorator()