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 -*- | |
| """ | |
| Example DAG to highlight testing process. | |
| Owner: Scott Cruwys (scruwys@activecampaign.com) | |
| Runs: @daily | |
| """ | |
| ############### Airflow dependencies ############### |
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 pandas | |
| import numpy as np | |
| import operator | |
| from itertools import compress | |
| from sklearn.tree import DecisionTreeClassifier | |
| from sklearn.feature_selection import RFE | |
| # monkey patch to add coef_ class variable... | |
| class DecisionTreeClassifierWithCoef(DecisionTreeClassifier): | |
| def fit(self, *args, **kwargs): |
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
| $.fn.extend({ | |
| submitAsync: function(params) { | |
| var method = $(this).attr('method'); | |
| var defaults = { | |
| type : ( method === undefined ) ? 'POST' : method, | |
| url : $(this).attr('action'), | |
| data : $(this).serialize(), | |
| dataType : 'json', | |
| encode : true | |
| }; |
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
| def levenshtein(string1, string2): | |
| if string1 == string2: | |
| return 0 | |
| # make sure string1 is larger than string2 | |
| if len(string1) < len(string2): | |
| return levenshtein(string2, string1) | |
| # if string2 is empty, then we know that the distance is | |
| # just the length of string1 | |
| if len(string2) == 0: | |
| return len(string1) |
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
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| import requests as req | |
| class GoogleTranslate(object): | |
| end_point = "https://www.googleapis.com/language/translate/v2" | |
| def __init__(self, key): |
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 bs4 import BeautifulSoup | |
| import requests | |
| import csv | |
| import re | |
| def write_to_tsv(filename, results): | |
| with open(filename, 'ab') as outfile: | |
| writer = csv.DictWriter(outfile, fieldnames=results[0].keys(), delimiter="\t") | |
| writer.writerows(results) |
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
| // needs better support for 4xx responses, but a good starting off point... | |
| var ajax = {}; | |
| ajax.build_payload = function(data) { | |
| var payload = []; | |
| // prepare to pass variables as URL string... | |
| for( var n in data ) { | |
| payload.push(encodeURIComponent(n) + '=' + encodeURIComponent(data[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
| # app/models/concerns/acts_as_trackable.rb | |
| module Trackable | |
| extend ActiveSupport::Concern | |
| module ActiveRecord | |
| def acts_as_trackable(field_name = nil) | |
| # create a reader on the class to access the field name | |
| class << self; attr_reader :displayable; end | |
| @displayable = field_name |
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
| # app/models/concerns/simple_search.rb | |
| module SimpleSearch | |
| extend ActiveSupport::Concern | |
| module ActiveRecord | |
| def simple_search | |
| include SimpleSearch | |
| end | |
| end |
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 requests | |
| from bs4 import BeautifulSoup | |
| class Crawler: | |
| def __init__(self, base_url): | |
| self.base_url = base_url | |
| # Returns raw HTML based on URL and parameters | |
| def get(self, url, payload={}): |
NewerOlder