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
// Pointers | |
int a = 3, b = 4; | |
int c = 1, d = 2; | |
int* pa = &a; | |
int e = *pa; |
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 java.util.Arrays; | |
import java.util.List; | |
import java.util.ArrayList; | |
// The following are required for implementing the Iterable and Iterator interfaces. | |
import java.lang.Iterable; | |
import java.util.Iterator; | |
import java.util.NoSuchElementException; | |
public class SeekableList<T> { |
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--; | |
} |
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
# 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
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
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
# 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
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
def remove_spans_neg(s, spans): | |
return ''.join(s[i:j] for (_, i), (j, _) in zip([(None,0)]+spans, spans+[(len(s),None)])) |