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 itertools import chain, starmap | |
def remove_spans(s, spans): | |
to_drop = set(chain(*starmap(range, spans))) | |
return ''.join(c for (i, c) in enumerate(s) if i not in to_drop) |
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 remove_spans_gen(s, spans): | |
checker = make_range_checker(spans); next(checker) | |
return ''.join(c for (i, c) in enumerate(s) if not checker.send(i)) | |
def make_range_checker(spans): | |
idx = yield | |
for (i, j) in spans: | |
while idx < j: | |
idx = (yield i <= idx < j) | |
while 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 remove_spans_neg(s, spans): | |
return ''.join(s[i:j] for (_, i), (j, _) in zip([(None,0)]+spans, spans+[(len(s),None)])) |
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
dept_prov_apt_types = DepartmentProviderAppointmentType.where("department_provider_id in (?)", @department_providers.map(&:id)) | |
@apt_types = AppointmentType.where("id in (?)", dept_prov_apt_types.map(&:appointment_type_id)).distinct.order(: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
# how to get python to look like this haskell?.. | |
# listOfTuples :: [(Int,Char)] | |
# listOfTuples = do | |
# n <- [1,2] | |
# ch <- ['a','b'] | |
# return (n,ch) | |
# -> [(1, 'a'), (1, 'b'), (2, 'a'), (2, 'b')] | |
# ..such that we can write a coroutine and apply a decorator that will make | |
@list_monad |
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 numpy as np | |
import pandas as ps | |
np.random.seed(0) | |
index=range(3) | |
columns = list('abc') | |
panel = ps.Panel.from_dict( | |
{'A' : ps.DataFrame(np.random.randn(3, 3), index=index, columns=columns), |
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 sklearn.feature_extraction import DictVectorizer | |
import pandas | |
def demo1(input_csv, new_csv): | |
"""Demonstration of one-hot encoding through Scikit-Learn's DictVectorizer object.""" | |
df = pandas.read_csv(input_csv) #read csv into a DataFrame object | |
#create the one hot encoder | |
one_hot_encoder = DictVectorizer(sparse=False) |
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
# If you are using anaconda, then you need to install an extra package which is used behind the scenes. | |
# Run the following command on the command line: | |
# | |
# $ conda install pymysql | |
# | |
# say yes when it prompts you. | |
import pandas | |
from sqlalchemy import create_engine |
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
public void updateWordCount(HashMap<String, Integer> counts, String wordToUpdate){ | |
if (counts.containsKey(wordToUpdate)) { | |
int current_count = counts.get(wordToUpdate); | |
counts.put(wordToUpdate, current_count++); | |
} else { | |
counts.put(wordToUpdate, 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
public class SynchronizedCounter { | |
private int c = 0; | |
public synchronized void increment() { | |
c++; | |
} | |
public synchronized void decrement() { | |
c--; | |
} |
OlderNewer