This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class StrKeyDict0(dict): | |
| def __missing__(self, key): | |
| if isinstance(key, str): | |
| raise KeyError(key) | |
| return self[str(key)] | |
| def get(self, key, default=None): | |
| try: | |
| return self[key] | |
| except KeyError: | |
| return default |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| import re | |
| WORD_RE = re.compile('\w+') | |
| index = {} | |
| with open(sys.argv[1], encoding='utf-8') as fp: | |
| for line_no, line in enumerate(fp, 1): | |
| for match in WORD_RE.finditer(line): | |
| word = match.group() | |
| column_no = match.start()+1 | |
| location = (line_no, column_no) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import bisect | |
| import random | |
| SIZE = 7 | |
| random.seed(1729) | |
| my_list = [] | |
| for i in range(SIZE): | |
| new_item = random.randrange(SIZE*2) | |
| bisect.insort(my_list, new_item) | |
| print('%2d ->' % new_item, my_list) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import bisect | |
| import sys | |
| HAYSTACK = [1, 4, 5, 6, 8, 12, 15, 20, 21, 23, 23, 26, 29, 30] | |
| NEEDLES = [0, 1, 2, 5, 8, 10, 22, 23, 29, 30, 31] | |
| ROW_FMT = '{0:2d} @ {1:2d} {2}{0:<2d}' | |
| def demo(bisect_fn): | |
| for needle in reversed(NEEDLES): | |
| position = bisect_fn(HAYSTACK, needle) | |
| offset = position * ' |' | |
| print(ROW_FMT.format(needle, position, offset)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| metro_areas = [ | |
| ('Tokyo', 'JP', 36.933, (35.689722, 139.691667)), | |
| ('Delhi NCR', 'IN', 21.935, (28.613889, 77.208889)), | |
| ('Mexico City', 'MX', 20.142, (19.433333, -99.133333)), | |
| ('New York-Newark', 'US', 20.104, (40.808611, -74.020386)), | |
| ('Sao Paulo', 'BR', 19.649, (-23.547778, -46.635833)), | |
| ] | |
| print('{:15} | {:^9} | {:^9}'.format('', 'lat.', 'long.')) | |
| fmt = '{:15} | {:9.4f} | {:9.4f}' | |
| for name, cc, pop, (latitude, longitude) in metro_areas: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Programa: rectangulo.py | |
| Propósito: Calcula el perímetro y el área de un rectángulo a partir de su altura y anchura. | |
| Autor: @soyluiscorona | |
| Fecha: 1/1/2020 | |
| Petición de los datos (en metros) | |
| altura float input | |
| anchura float input |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function longCode() { | |
| var tStart = Number(new Date()); | |
| while( (tStart + 5000) > Number(new Date()) ) {}; } | |
| window.onload = longCode; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://docs.npmjs.com/cli/install | |
| # 1 | |
| npm install <protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish>] | |
| ## Examples | |
| npm install git+https://[email protected]/visionmedia/express.git | |
| npm install git+https://[email protected]/visionmedia/express.git#branch | |
| # 2 | |
| npm install <githubname>/<githubrepo>[#<commit-ish>] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function addHandler(target, eventType, handler){ | |
| //overwrite the existing function | |
| if (target.addEventListener){ //DOM2 Events | |
| addHandler = function(target, eventType, handler){ | |
| target.addEventListener(eventType, handler, false); | |
| }; | |
| } else { //IE | |
| addHandler = function(target, eventType, handler){ | |
| target.attachEvent("on" + eventType, handler); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function parseJSON(responseText) { | |
| var users = []; | |
| var usersArray = eval('(' + responseText + ')'); | |
| for (var i = 0, len = usersArray.length; i < len; i++) { | |
| users[i] = { | |
| id: usersArray[i][0], | |
| username: usersArray[i][1], | |
| realname: usersArray[i][2], | |
| email: usersArray[i][3] | |
| }; |