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 { fetchEventData, IFetchOptions } from 'fetch-sse' | |
| // Defines the options for running a workflow, including an optional data handler. | |
| export interface FetchEventStreamOptions extends IFetchOptions { | |
| onData?: (json: any) => void | |
| } | |
| // Extends FetchEventStreamOptions to include user-specific and workflow control options. | |
| export interface WorkflowOptions extends FetchEventStreamOptions { | |
| body: { |
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
| from operator import getitem | |
| from functools import reduce | |
| def getindex(array, index, default=None): | |
| ''' | |
| getindex(['foo', 'bar'], 1) => 'bar' | |
| getindex(['foo', 'bar'], 2) => None | |
| ''' | |
| try: | |
| return array[index] |
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
| const request = (url, options) => | |
| fetch(url, { | |
| 'Content-Type': 'application/json', | |
| ...options | |
| }) | |
| .then(response => { | |
| if (response.ok) return response.json() | |
| throw new Error(response.status) | |
| }) |
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
| # -*- coding: utf-8 -*- | |
| class Imposto(object): | |
| def __init__(self, rendimento_anual_bruto): | |
| self.rendimento_anual_bruto = rendimento_anual_bruto | |
| self.rendimento_anual_de_incidencia = self.rendimento_anual_bruto * self.TAXA_DE_INCIDENCIA | |
| self.rendimento_mensal_bruto = rendimento_anual_bruto /12 | |
| self.rendimento_mensal_de_incidencia = self.rendimento_anual_de_incidencia /12 | |
| class SegurancaSocial(Imposto): |
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 Dictionary(dict): | |
| ''' | |
| d = Dictionary( {'foo': {'bar': 'foo'}} ) | |
| >>> d['foo']['bar'] | |
| 'foo' | |
| >>> d['foo']['foo']['bar'] | |
| {} | |
| instead of: | |
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 socket | |
| def import_settings(configs={}, default=None, base=None): | |
| ''' | |
| Args: | |
| configs - dictionary of {hostname : settings-module} - settings mapped to current hostname is loaded. | |
| default - settings-module - loaded if current hostname not in configs. | |
| base - settings-module - loaded regardless of the other args. | |
| import_settings( |
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
| from django.conf.urls import include, patterns, url as django_url | |
| import re | |
| def url(pattern, view, kwargs=None, name=None, prefix='', constraints={}): | |
| ''' | |
| url('/path/:id/to/:something/', some_view, constraints={'id': r'\d{4}'}) | |
| ''' | |
| def convert(match): | |
| name = match.group(1) |
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
| from requests import post | |
| import re, json, optparse | |
| class GeoIpCity: | |
| @staticmethod | |
| def request( ip ): | |
| response = post( "http://www.maxmind.com/app/lookup_city", {'ips': ip} ) | |
| return ''.join( [i.strip() for i in response.content.split('\n')] ) | |
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
| from requests import get | |
| import re, json, optparse | |
| class WhatIsMyIP: | |
| @staticmethod | |
| def request( ip ): | |
| clean_html = lambda x: ''.join( [ i.strip() for i in x.split('\n')] ) | |
| url = lambda x: "http://whatismyipaddress.com/ip/%s" %x | |
| response = get( url(ip), headers={'User-Agent': 'Mozilla/5.0'} ) |
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
| from unicodedata import normalize, combining | |
| def unicode_( s ): | |
| """ | |
| Convert string to unicode & Remove accents | |
| """ | |
| ustr = u''.join( ucharlist( '%s'%s ) ) | |
| nkfd = normalize( 'NFKD', ustr ) | |
| return u''.join( [ c for c in nkfd if not combining(c) ] ) |
NewerOlder