Skip to content

Instantly share code, notes, and snippets.

View suzukimilanpaak's full-sized avatar

Tatsuya Suzuki suzukimilanpaak

  • Manchester, UK
  • 11:06 (UTC +01:00)
View GitHub Profile
@viveksoundrapandi
viveksoundrapandi / .py
Last active May 19, 2020 08:36
Forwardable in python
class Forwardable(object):
def __init__(self, *args, **kwargs):
self._delegates = []
return super().__init__(*args, **kwargs)
@property
def delegates(self):
return self._delegates
@delegates.setter
import collections
def sample():
# point 1. 属性はデコレータに文字列で与える。
@immutable(
'x1', 'y1', 'x2', 'y2',
'is_rectangle', 'is_line', 'is_dot')
class Region(object):
# point 2. __init__ ではなく、__new__ を使う。
@diegopacheco
diegopacheco / main.tf
Last active August 14, 2021 19:08
Terraform + Localstack
provider "aws" {
region = "us-west-2"
access_key = "anaccesskey"
secret_key = "asecretkey"
skip_credentials_validation = true
skip_metadata_api_check = true
s3_force_path_style = true
endpoints {
s3 = "http://119.18.0.101:4572"
}
@giannisp
giannisp / gist:ebaca117ac9e44231421f04e7796d5ca
Last active March 1, 2024 14:39
Upgrade PostgreSQL 9.6.5 to 10.0 using Homebrew (macOS)
After automatically updating Postgres to 10.0 via Homebrew, the pg_ctl start command didn't work.
The error was "The data directory was initialized by PostgreSQL version 9.6, which is not compatible with this version 10.0."
Database files have to be updated before starting the server, here are the steps that had to be followed:
# need to have both 9.6.x and latest 10.0 installed, and keep 10.0 as default
brew unlink postgresql
brew install postgresql@9.6
brew unlink postgresql@9.6
brew link postgresql
@ryanmaclean
ryanmaclean / salt_on_mac.md
Last active March 10, 2024 10:38
Install and Run Salt Stack on macOS Servers and Desktops

Install Salt on macOS

Install Homebrew

Install Dependencies

brew install python swig zmq
@pgolding
pgolding / streamingbody.md
Last active January 30, 2024 16:28
Handling of StreamingBody Response from Invoking a Lambda Function

Handling of StreamingBody Response from Invoking a Lambda Function

When calling a Lambda Function via Boto3, the returned object is something like:

{u'Payload': <botocore.response.StreamingBody object at 0x7f8d5b62ac50>, 
'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': '5bdbb3ca-3b35-11e7-9816-397b140c3bac', 'HTTPHeaders': {'x-amzn-requestid': '5bdbb3ca-3b35-11e7-9816-397b140c3bac', 'content-length': '1636', 'x-amzn-trace-id': 'root=1-591ca199-00d34d5474d16275ec2c8d10;sampled=0', 'x-amzn-remapped-content-length': '0', 'connection': 'keep-alive', 'date': 'Wed, 17 May 2017 19:16:41 GMT', 'content-type': 'application/json'}}, u'StatusCode': 200}

The Payload parameter is <botocore.response.StreamingBody> which is a data streaming object.

@cristipufu
cristipufu / producer_consumer.py
Created March 1, 2017 00:35
Producer-consumer problem in python
import sys
import random
import time
from threading import *
class Producer(Thread):
def __init__(self, items, can_produce, can_consume):
Thread.__init__(self)
self.items = items
self.can_produce = can_produce
@morishin
morishin / 1-uistackview-in-uiscrollview.playground.swift
Last active May 17, 2021 06:35
Example: UIStackView in UIScrollView
import UIKit
import PlaygroundSupport
let scrollView = UIScrollView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
scrollView.backgroundColor = .red
let stackView = UIStackView(frame: CGRect(x: 0, y: 0, width: 1000, height: 100))
stackView.backgroundColor = .gray
stackView.axis = .horizontal
stackView.spacing = 10
@ntamvl
ntamvl / install-squid-proxy-server-on-ubuntu-14-04.md
Last active January 6, 2019 08:52
Install Squid proxy server on Ubuntu 14.04

Install Squid proxy server on Ubuntu 14.04

Installing Squid

Squid is available in the Ubuntu repositories. To ensure your system is up to date and then to install Squid, run the following commands:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install squid

Copy the original configuration file to keep as a backup:

Question: Given a sequence of positive integers A and an integer T, return whether there is a continuous sequence of A that sums up to exactly T Example [23, 5, 4, 7, 2, 11], 20. Return True because 7 + 2 + 11 = 20 [1, 3, 5, 23, 2], 8. Return True because 3 + 5 = 8 [1, 3, 5, 23, 2], 7 Return False because no sequence in this array adds up to 7

Note: We are looking for an O(N) solution. There is an obvious O(N^2) solution which is a good starting point but is not the final solution we are looking for.