After updating Ubuntu from 14.04 to 16.0…
PostgreSQL: could not connect to server
When I started PostgreSQL server with sp…
JavaScript: UI test with Nightmare, mocha, and chai
with mocha-generators plugin [crayon-600…
LINE BOT: 終電君
終電の時刻を調べてくれるLINE BOTです。FlaskとHerokuで動かして…
Daily MagicEye App is now available on Play Store!
Daily MagicEye App is now available!
JavaScript: Window resize event in MarionetteJS
1 2 3 4 5 6 7 8 9 10 |
var ImageView = Marionette.ItemView.extend({ initialize: function() { $(window).on('resize.imageview', this.onResize.bind(this)); }, onDestroy: function() { $(window).off('resize.imageview'); }, onResize: function() { // add resize event here }, |
WebService: Daily MagicEye
Random text magiceye page for daily visu…
Linux: Resize wubi’s virtual disk
1. Check the wubi’s virtual disk f…
Python: add attribute to MagicMock
1 2 3 4 5 6 7 8 9 10 |
>>> from unittest.mock import MagicMock >>> foo = MagicMock(attr1='spam', attr2='ham', attr3='eggs') >>> foo <MagicMock id='3059559436'> >>> foo.attr1 'spam' >>> foo.attr2 'ham' >>> foo.attr3 'eggs' |
CheckIO: Repeating decimals
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
def convert(numerator, denominator): to_str = lambda L: ''.join(map(str, L)) decimals, remains = [], [] integer, remain = numerator // denominator, numerator % denominator remains.append(remain) while True: quotient, remain = remain * 10 // denominator, remain * 10 % denominator decimals.append(quotient) if not remain: # doesn't repeat if sum(decimals): return '{}.{}'.format(integer, to_str(decimals)) else: return '{}.'.format(integer) if remain in remains: # repeat found repeat_start = remains.index(remain) non_repeat, repeat = decimals[:repeat_start], decimals[repeat_start:] return '{}.{}'.format( integer, to_str(non_repeat) + '({})'.format(to_str(repeat)) ) else: remains.append(remain) if __name__ == '__main__': #These "asserts" using only for self-checking and not necessary for auto-testing assert convert(1, 3) == "0.(3)", "1/3 Classic" assert convert(5, 3) == "1.(6)", "5/3 The same, but bigger" assert convert(3, 8) == "0.375", "3/8 without repeating part" assert convert(7, 11) == "0.(63)", "7/11 prime/prime" assert convert(29, 12) == "2.41(6)", "29/12 not and repeating part" assert convert(11, 7) == "1.(571428)", "11/7 six digits" assert convert(0, 117) == "0.", "Zero" |
https:/…