Skip to content

Instantly share code, notes, and snippets.

View suzukimilanpaak's full-sized avatar

Tatsuya Suzuki suzukimilanpaak

  • Manchester, UK
  • 17:10 (UTC +01:00)
View GitHub Profile
@suzukimilanpaak
suzukimilanpaak / openstruct.py
Created May 23, 2020 18:20
Ruby's Openstruct alternative in Python
class OpenStruct:
def __init__(self, **dic):
self.__dict__.update(dic)
def __getattr__(self, i):
if i in self.__dict__:
return self.__dict__[i]
else:
None
def __setattr__(self,i,v):
if i in self.__dict__:
@suzukimilanpaak
suzukimilanpaak / delegatable.py
Last active May 29, 2020 07:11 — forked from viveksoundrapandi/.py
Delegatable in python
# -*- coding: utf-8 -*-
'''
Convenient classes to enable delegate
..codeauthor Tatsuya Suzuki <tatsuya.suzuki@nftlearning.com>
'''
import copy
import logging as log
from typing import Sequence, Any, Dict, Tuple
# def delegatable(cls):
class MessagesViewController: UIViewController {
func addButton(text: String) {
let button = generateButton(from: String(text))
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
self.buttons.append(button)
}
func layoutButtons() {
buttonView?.removeFromSuperview()
@suzukimilanpaak
suzukimilanpaak / 0.url.txt
Last active January 17, 2018 06:48
県を一つ指定して検索した場合
/search?category_id=7&prefecture_ids%5B%5D=12&occupation_id=54
@suzukimilanpaak
suzukimilanpaak / 0.質問.md
Last active December 20, 2017 08:12
言語学に関する質問
@suzukimilanpaak
suzukimilanpaak / try.swift
Created March 23, 2017 06:55
[Swift] try, try!, try?
import Foundation
enum ThrowableError: Error { case BadError }
func doSomething(_ occursError: Bool) throws -> String {
if !occursError {
return "Everything is ok"
} else {
throw ThrowableError.BadError
}
@suzukimilanpaak
suzukimilanpaak / note.sql
Last active August 29, 2016 07:12
食べ方の定義に関する食材を除く
select *, (probability * 91) from dish_ingredients where dish = 'すき焼き' and modifier = '' order by probability desc;
select *, (probability * 79) from dish_ingredients where dish = 'オムライス' and modifier = '' order by probability desc;
select *, (probability * 104) from dish_ingredients where dish = 'カレーライス' and modifier = '' order by probability desc;
select *, (probability * 93) from dish_ingredients where dish = 'チャーハン' and modifier = '' order by probability desc;
select *, (probability * 93) from dish_ingredients where dish = '冷やし中華' and modifier = '' order by probability desc;
select *, (probability * 91) from dish_ingredients where dish = '南蛮漬け' and modifier = '' order by probability desc;
select *, (probability * 68) from dish_ingredients where dish = '生姜焼き' and modifier = '' order by probability desc;
select *, (probability * 78) from dish_ingredients where dish = '餃子' and modifier = '' order by probability desc;
@suzukimilanpaak
suzukimilanpaak / problem.md
Last active March 12, 2018 16:41
PARKING LOT PROBLEM

####################################################################################

PARKING LOT PROBLEM

Rules of the Game

  1. You have two full days to implement a solution
  2. You can use any (fairly) mainstream object oriented language of your choice, so long as your solution builds and runs on linux. You should be fine if you favour, say, Java, Ruby, Python or Javascript.
  3. Please ensure that you follow the syntax and formatting of both the
@suzukimilanpaak
suzukimilanpaak / example.js
Created February 12, 2016 06:47
bindの動作
var classExample = {
binded: function(){ console.info(this) }.bind(this),
unBinded: function(){ console.info(this) }
}
classExample.binded();
// => Window {external: Object, chrome: Object, document: document, React: Object, ReactDOM: Object…}
classExample.unBinded();
// => Object { binded: function(){ console.info(this) }.bind(this), unBinded: function(){ console.info(this) }}

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.