104 Matching Annotations
  1. Last 7 days
    1. #!/usr/bin/env python3 import configparser import os import sys from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.keys import Keys from selenium.common.exceptions import TimeoutException from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By config = configparser.ConfigParser() config.read("config.ini") chrome_options = Options() chrome_options.add_argument("--headless") driver = webdriver.Chrome(executable_path=os.path.abspath("/usr/local/bin/chromedriver"), chrome_options=chrome_options) driver.get("https://fastmail.fm") timeout = 120 try: element_present = EC.presence_of_element_located((By.NAME, 'username')) WebDriverWait(driver, timeout).until(element_present) # Send login information user = driver.find_element_by_name("username") passwd = driver.find_element_by_name("password") user.send_keys(config["default"]["user"]) passwd.send_keys(config["default"]["pass"]) driver.find_element_by_class_name("v-Button").click() print("Logged in") # wait for login to complete element_present = EC.presence_of_element_located((By.CLASS_NAME, 'v-MainNavToolbar')) WebDriverWait(driver, timeout).until(element_present) # click settings menu to make elements visible driver.find_element_by_class_name("v-MainNavToolbar").click() # And follow to settings page driver.find_element_by_link_text("Settings").click() # Wait for settings page to render, oh Javascript element_present = EC.presence_of_element_located((By.LINK_TEXT, 'Rules')) WebDriverWait(driver, timeout).until(element_present) # Click on Rules link driver.find_element_by_link_text("Rules").click() # Click on edit custom sieve code element_present = EC.presence_of_element_located((By.LINK_TEXT, 'Edit custom sieve code')) WebDriverWait(driver, timeout).until(element_present) driver.find_element_by_link_text("Edit custom sieve code").click() print("Editing") # This is super unstable, I hate that we have to go by webid element_present = EC.presence_of_element_located((By.CLASS_NAME, 'v-EditSieve-rules')) WebDriverWait(driver, timeout).until(element_present) print("Find form") elements = driver.find_elements_by_css_selector("textarea.v-Text-input") element = elements[-1] # Find the submit button elements = driver.find_elements_by_css_selector("button") for e in elements: if "Save" in e.text: submit = e print("Found form") # And replace the contents element.clear() with open("rules.txt") as f: element.send_keys(f.read()) # This is the Save button print("Submitted!") submit.click() except TimeoutException as e: print(e) print("Timed out waiting for page to load") sys.exit(0) print("Done!")
  2. Apr 2019
  3. Mar 2019
  4. Feb 2019
  5. Jan 2019
    1. MIT “MATLAB is the language used by virtually every team in the world that designs gravitational wave detectors… I look forward to exploring the data from each new detection in MATLAB.” Matthew Evans, Assistant Professor of Physics
    1. KNIME includes Python in various processing nodes for data processing, model learning and prediction, and the generation of visualizations.
  6. Dec 2018
  7. Nov 2018
  8. Oct 2018
    1. All you can do is send a message (AYCDISAM) = Actors model - there is no direct manipulation of objects, only communication with (or invocation of) them. The presence of fields in Java violates this.

      from what I understand in Java... there are some variables on classes (class instances) that are only acessible through methods and for those the "only send message" paradigm holds but there are also fields which are like attributes in python which you can change directly

  9. Aug 2018
  10. Jul 2018
  11. Jun 2018
    1. With over 6 million users, the open source Anaconda Distribution is the fastest and easiest way to do Python and R data science and machine learning on Linux, Windows and Mac OS X. It's the industry standard for developing, testing and training on a single machine

      With over 6 million users, the open source Anaconda Distribution is the fastest and easiest way to do Python and R data science and machine learning on Linux, Windows and Mac OS X. It's the industry standard for developing, testing and training on a single machine

    1. Project Jupyter exists to develop open-source software, open-standards, and services for interactive computing across dozens of programming languages

  12. May 2018
    1. 如果不在同一个package中,例如我们希望在module_21.py中调用module_11.py中的FuncA
      from module_11包名.module_11 import funcA
      
    1.   这两个函数都接收一个分割字符串作为参数,将目标字符串分割为两个部分,返回一个三元元组(head,sep,tail),包含分割符。细微区别在于前者从目标字符串的末尾也就是右边开始搜索分割符。
      >>> "django.core.app".partition('.')
      ('django', '.', 'core.app')
      >>> "django.core.app".rpartition('.')
      ('django.core', '.', 'app')
      
    1. argarse.ArgumentParser.parse_known_args()解析

      有时脚本可能只解析一些命令行参数,将剩下的参数传递给另一个脚本或程序。 在这种情况下,parse_known_args() 方法可能很有用。 它的工作方式与parse_args() 非常相似,只是在出现额外参数时不会产生错误。 相反,它会重新生成包含已填充名称空间和剩余参数字符串列表的两个项目元组。

      import argparse  
      parser = argparse.ArgumentParser()  
      parser.add_argument(  
          '--flag_int',  
          type=float,  
          default=0.01,  
          help='flag_int.'  
      )  
      FLAGS, unparsed = parser.parse_known_args()  
      print(FLAGS)  
      print(unparsed)
      
      # python test.py --flag_int 1 --flag_bool True --flag_string 'haha, I get it' --flag_float 0.2
      
      Namespace(flag_int=1.0)
      ['--flag_bool', 'True', '--flag_string', 'haha, I get it', '--flag_float', '0.2']
      
    1. one level is chosen as the “reference”, and its mean behaviour is represented by the intercept. Each column of the resulting matrix represents the difference between the mean of one level and this reference level
  13. Apr 2018
    1. Iterator Protocol

      The protocol specifies methods to be implemented to make our objects iterable.

      该协议指定了要实现我们的对象迭代的方法。

      "Iterable" simply means able to be looped over or otherwise treated as a sequence or collection.

      “可迭代”仅仅意味着能够循环或像对待序列或集合一样的方式处理。

    2. Classes allow us to create a custom type of object -- that is, an object with its own behaviors and its own ways of storing data.

      Introduction of Classes 类允许我们创建一个自定义类型的对象 - 也就是说,一个对象具有自己的行为和自己的存储数据的方式。

    3. Packages provide for accessing variables within multiple files.

      从package多文件访问变量的注意事项

    4. A package is a directory of files that work together as a Python application or library module.

      Introduction python packages

      packages是一个文件目录,可以作为Python应用程序或库模块一起工作

    5. Recursion features three elements

      递归调用三要素:

      1. recursive call: 递归调用,这是函数对自己的调用;
      2. function process: 函数过程本身;
      3. base condition: 一个基本条件,这是递归链最终返回的点。
    6. *args and **kwargs to capture all arguments

      *args 和 **kwargs 可以代表所有参数

      为了允许装饰函数接受参数,我们必须接受它们并将它们传递给装饰函数。

    7. object: a data value of a particular type variable: a name bound to an object

      什么是object -- 是一个具有类型的数据 什么是变量 -- 是一个绑定对象的名字

    8. All programs named test_something.py that have functions named test_something()

      pytest Basics

    9. unit test: testing individual units (function/method) integration test: testing multiple units together regression test: testing to see if changes have introduced errors end-to-end test: testing the entire program
      • 单元测试 -- 测试单个单元,方法
      • 集成测试 -- 集中测试多个单元
      • 回归测试 -- 测试修改有没有引入新的错误
      • 端到端测试 -- 测试整个程序
    10. pandas is a Python module used for manipulation and analysis of tabular data.

      Introduction to Pandas

      Pandas is used to manipulation and analysis of tabular data

    11. pandas official documentation

      pandas reference and tutorials include:full docs, 10minutes to pandas, blog tutorials

    1. JupyterHub, a multi-user Hub, spawns, manages, and proxies multiple instances of the single-user Jupyter notebook server.
    1. What is music21?

      ¿Qué es Music21?

      Music21 es un conjunto de herramientas para ayudar a los estudiantes de música y personas que escuchan la música de manera activa a resolver preguntas cómo: ¿Cuántas veces hace Bach eso? ¿cuándo fue la primera vez que determinada banda uso cierto orden de acordes?.

    2. How simple is music21 to use?

      ¿Cómo usar Music21?

      Después de instalar python y music21 usando pip u otro método, escribir en un archivo de texto: "from music21 import*" y luego puedes trabajar con todas las funciones que ofrece la biblioteca music21

      Para mostrar una melodía en notación musical se escribe: converter.parse("tinynotation: 3/4 c4 d8 f g16 a g f#").show()

    1. At every turn, IPython chose the way that was more inclusive, to the point where it’s no longer called “IPython”: The project rebranded itself as “Jupyter” in 2014 to recognize the fact that it was no longer just for Python.

      Such an interesting progression!

  14. Nov 2017
    1. Compilers translate an entire program's source code before the program can run. Interpreters translate one line at a time but it doesn't mean that the compilation stage doesn't happen.

    1. At some point in the following decade json-head.appspot.com stopped working. Today I’m bringing it back, mainly as an excuse to try out the combination of Python 3.5 async, the Sanic microframework and Zeit’s brilliant Now deployment platform.

      Oh neat, I had no idea now supported Python. Another option available!

  15. Oct 2017
    1. c = np.full((2,2), 7) # Create a constant array print(c)

      To avoid the warning, use

      np.full((2,2), 7.) or use explicitly for float np.full((2,2),7, dtype=float) or for int np.full((2,2),7, dtype=int)

  16. Sep 2017
    1. However, unlike an ordinary loop, yield from allows subgenerators to receive sent and thrown values directly from the calling scope, and return a final value to the outer generator

      This is the main usage of yield from.

    1. Spectral Python (SPy) is a pure Python module for processing hyperspectral image data. It has functions for reading, displaying, manipulating, and classifying hyperspectral imagery. It can be used interactively from the Python command prompt or via Python scripts
    1. PostgreSQL連接Python

      python连接postgresql,非常简单,基本跟mylsql一样,通过cursor来执行

  17. Jul 2017
  18. Jun 2017
    1. Shannon held up a BBC micro:bit board, which runs MicroPython and has been given to students in the UK, and noted that it only has 16KB of memory.

      check out MicroPython

  19. May 2017
    1. Calling from Python As of 10.10, AppleScript can use Cocoa frameworks in any Script Editor-based script. This makes it easy for Python and other languages that have Objective-C bridges to call AppleScript directly, without having to package everything as an Xcode app. Stick one or more compiled .scpt files containing AppleScript-ObjC "classes" into a folder, e.g.: use framework "Foundation" use scripting additions script MyASClass property parent : class "NSObject" -- on test() activate display dialog "Hello from AppleScript!" end test end script then just use it from Python like this: from Foundation import NSBundle, NSClassFromString import AppleScriptObjC NSBundle.alloc().initWithPath_(FOLDERPATH).loadAppleScriptObjectiveCScripts() MyASClass = NSClassFromString(u"MyASClass") # get the ASOC class... MyASClass.alloc().init().test() # ...then instantiate and call it

      Given that appscript is deprecated, I'm looking at how to call AppleScript directly from Python. This section is a "hello world" demonstration of how.

  20. Apr 2017
  21. Mar 2017
    1. Prophet : Facebook에서 오픈 소스로 공개한 시계열 데이터의 예측 도구로 R과 Python으로 작성되었다.

      python statics opensource, also can use R

  22. Feb 2017
  23. Jan 2017
    1. However, remember that Click is Unicode-based, so the string will always be a Unicode value
    1. In Python, as well as in any other object-oriented programming language, we define a class to be a description of what the data look like (the state) and what the data can do (the behavior). Classes are analogous to abstract data types because a user of a class only sees the state and behavior of a data item. Data items are called objects in the object-oriented paradigm. An object is an instance of a class.

      Class = General description of form and functions of data. Object = A member or instance of a class.

  24. Dec 2016
    1. In that case, you need an empty placeholder list that you can append items to individually.

      这涉及到之后的关于automatioin的程序功能。programming最厉害的地方就在于automation。

  25. Nov 2016
    1. Mastodon.py Documentation

      Python/API documentation for the Mastodon social networking platform.

  26. Sep 2016
  27. Aug 2016
  28. Jul 2016
    1. True.

      a = np.array(1) # 0-d, but different from np.int64(1)

      b = np.array([1]) # 1-d, same as a.reshape((1))

      c = np.array([[1]]) # 2-d, same as a.reshape((1,1))

  29. Jun 2016
    1. Remember that a slicing tuple can always be constructed as obj and used in the x[obj] notation. Slice objects can be used in the construction in place of the [start:stop:step] notation. For example, x[1:10:5,::-1] can also be implemented as obj = (slice(1,10,5), slice(None,None,-1)); x[obj] . This can be useful for constructing generic code that works on arrays of arbitrary dimension.
  30. Apr 2016
    1. That’s probably the Dropbox server. Two million lines of code and counting, and it serves hundreds of millions of users.

      I wonder what the biggest pain points are in maintaining a code base of this size in Python besides typing and performance, which Dropbox are already addressing via mypy and Pyston respectively.

    2. I want Python to be more effective for large projects, without losing sight of its use for small projects and teaching. It’s quite a challenge; my current hope lies in PEP 484 and mypy, an approach to optional static typing (a.k.a. gradual typing). It’s super exciting. There are also other things happening in the community that make Python faster.
  31. Feb 2016
    1. The rule of thumb is to avoid using more than two expressions in a list comprehension. This could be two conditions, two loops, or one condition and one loop. As soon as it gets more complicated than that, you should use normal if and for statements and write a helper function
    2. Dictionaries and sets have their own equivalents of list comprehen-sions.

      It gets better an better!

      d = { "foo": "bar", "baz": "qux" }
      r = {val: key for key, val in d.items()}
      #=> { "bar": "foo", "qux": "baz" }
      
    3. Unlike map, list comprehensions let you easily filter items from the input list, removing corresponding outputs from the result.

      This might be the greatest advantage of list comprehensions. Even in Ruby requires one to return a nil value from a map and then a call to compact, like: array.map(&:transform).compact.

    4. Beware that indexing a list by a negative variable is one of the few situations in which you can get surprising results from slicing. For example, the expression so melist[-n:] will work fine when n is greater than one (e.g., somelist[-3:]). However, when n is zero, the expression so melist[-0:] will result in a copy of the original list.

      Which is the same for somelist[:]. Not sure what the author is getting at. Maybe he meant to say that using variables as indexes when slicing can become confusing?

    5. Slicing can be extended to any Python class that implements the__getitem__ and __setitem__ special methods
    6. In a file, functions and classes should be separated by two blank lines.

      I wonder what the reasoning for having two blank lines for separating functions and one blank line for methods is. Seems like an arbitrary distinction.

  32. Dec 2015
    1. The basic principle is that you patch where an object is looked up, which is not necessarily the same place as where it is defined. A couple of examples will help to clarify this.

      This caught me out, as it did for a lot of other people apparently, see also this useful post about Python Mock gotchas: http://alexmarandon.com/articles/python_mock_gotchas/

  33. Nov 2015
    1. Given we put the system in a known state before the user (or external system) starts interacting with the system (in the When steps). Avoid talking about user interaction in givens. When we take key actions the user (or external system) performs. This is the interaction with your system which should (or perhaps should not) cause some state to change. Then we observe outcomes.
  34. Oct 2015
  35. Jul 2015
  36. May 2015
  37. Mar 2015
    1. Python is in fact compiled to bytecode
    2. A now-famous early usage of Python was in 1996: Google’s first successful web crawler.

      It is interesting to know that this fact on Python!

  38. Nov 2014
    1. Python was created by Guido Van Rossum in the early 90s. It is now one of the most popular languages in existence. I fell in love with Python for its syntactic clarity. It’s basically executable pseudocode.

      Helpful concise, Python syntax doc

    1. The goal of this site is to provide a set of materials in support of my Python for Informatics: Exploring Information book to allow you to learn Python on your own. This page serves as an outline of the materials to support the textbook.

      http://www.pythonlearn.com/ | A great resource for starting programmers looking to build knowledge and gain skills. Open Source Course

  39. Feb 2014
    1. The hard part is teaching the consequences of each choice.

      Once you get the syntax and basic language idioms out of the way this is the real problem that faces us no matter what language we pick.

  40. Dec 2013
    1. Read about how to use all of the things you installed.

      pip = A tool for installing and managing Python packages nose = A testing package for Python virtualenv = A Virtual Python Environment builder; helps you avoid updating libraries when you shouldn't distribute= Easily download, build, install, upgrade, and uninstall Python packages

  41. Nov 2013
    1. A class instance has a namespace implemented as a dictionary which is the first place in which attribute references are searched. When an attribute is not found there, and the instance’s class has an attribute by that name, the search continues with the class attributes.

      This search in namespaces -- first in the class instance and then in the class -- is documented here. Perhaps easier to understand by reading http://stackoverflow.com/a/15992667/7782

    1. Compared with the 1.0 release, there were relatively few backwards incompatible changes, but there are still a few issues to be aware of with this major release.

      I got all panicky when installing internetarchive via pip caused a move from requests 1.1.0 to 2.0.x -- I had thought that jump was the BIG ONE that broke a lot of other modules. Maybe not.

  42. Oct 2013
    1. The ability to seamlessly insert IPython notebooks into posts was one of the biggest drivers of my switch to Pelican.

      I want to study how Jake integrates IPython notebooks into his blogging. I'll be writing a lot in IPython notebook for my teaching.

    1. Three things are required to fully guarantee a repeatable installation using requirements files.

      "Ensuring Repeatability"