Skip to content

Instantly share code, notes, and snippets.

View rohan-varma's full-sized avatar

Rohan Varma rohan-varma

View GitHub Profile
def classify(cell_feature_vector, sickle_cluster, red_cluster, white_cluster):
#first, get the minimum of the distances to the known centroids.
sickle_dist = dist(cell_feature_vector, sickle_cluster.centroid)
red_dist = dist(cell_feature_vector, red_cluster.centroid)
white_dist = dist(cell_feature_vector, white_cluster.centroid)
min_dist = min(sickle_dist, red_dist, white_dist)
#check which centroid minimized the distance, and then check if this minimum distance is less than the furthest outlier
#that was still correctly classified.
//required objects
import {
GraphQLSchema,
GraphQLObjectType,
GraphQLID,
GraphQLString,
GraphQLNonNull,
GraphQLList,
GraphQLInterfaceType,
} from 'graphql';
const pokemonType = new GraphQLObjectType({
name: 'pokemon',
fields: () => ({
id: {type: GraphQLString},
name: {type: GraphQLString},
thumbnail: {type: GraphQLString}
}),
});
const Query = new GraphQLObjectType({
name: 'Query',
//our server can return pokemon and moves.
fields: {
pokemon: {
type: pokemonType, //the type we defined earlier
args: {
id: {type: GraphQLString} //an id can be passed in to the query to select the pokemon needed.
},
resolve: (_,args) => data[args.id], //uses the id as a key to fulfill the request. Note that if there's no id passed in,
const Schema = new GraphQLSchema({
query: Query //defined above
});
export default Schema;
{
pokemon(id: "1") {
name
thumbnail
id
}
}
const pokemonType = new GraphQLObjectType({
name: 'pokemon',
fields: () => ({
id: {type: GraphQLString},
name: {type: GraphQLString},
thumbnail: {type: GraphQLString},
//our favoriteMove is a moveType, which was defined earlier.
favoriteMove: {
type: moveType,
resolve: (parent, _) => moves[parent.id], //defines how this query is fulfilled.
ajax.get('http://website.com/api/v1/pokemonlightweight/1')
.done((data) => {
const moveIDString = getMoveString(data); //parse the move id from the response
ajax.get('http://website.com/api/v1/moves/${moveIDString}')
.done((data) => { //process the favorite move data
});
});
int* getProductsOfAllIntsExceptAtIndex(int* arr, int len) {
int* x = new int[len];
for(int i = 0 ; i < len ; i++) {
x[i] = getProduct(arr, len, i);
}
return x;
}
int getProduct(int* arr, int len, int index) {
//return product of all ints except at that index
int prod = 1;
for(int i = 0 ; i < len; i++) {
if(i!=index) {
prod*=arr[i];
}
}
return prod;
}