Skip to content

Instantly share code, notes, and snippets.

Avatar

Ayla Khan a-y-khan

  • Salt Lake City, UT, USA
View GitHub Profile
@a-y-khan
a-y-khan / optimized_queens.pl
Last active Mar 11, 2020
Eight Queens solutions from Seven Languages in Seven Weeks, SWI-Prolog version
View optimized_queens.pl
%% https://www.swi-prolog.org/man/clpfd.html
:- use_module(library(clpfd)).
%% ---
%% Excerpted from "Seven Languages in Seven Weeks",
%% published by The Pragmatic Bookshelf.
%% Copyrights apply to this code. It may not be used to create training material,
%% courses, books, articles, and the like. Contact us if you are in doubt.
%% We make no guarantees that this code is fit for any purpose.
%% Visit http://www.pragmaticprogrammer.com/titles/btlang for more book information.
@a-y-khan
a-y-khan / pandas_1_0_highlights.ipynb
Created Feb 27, 2020
Pyladies lightning talk: interesting new features in Pandas 1.0
View pandas_1_0_highlights.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View simple_json_to_df.py
import dask.bag as db
import json
json_bag = db.read_text('test.txt').map(json.loads)
dask_df = json_bag.to_dataframe()
print(dask_df.info())
print(dask_df.head(3))
pandas_df = dask_df.compute()
print(pandas_df.info())
View simple_json_generator.py
import json
def parse_line(file_object):
while True:
line = file_object.readline()
if not line:
break
yield json.loads(line)
with open('test.txt', 'r') as file_reader:
@a-y-khan
a-y-khan / sudoku4.pl
Last active Mar 11, 2020
Sudoku solution from Seven Languages in Seven Weeks, SWI-Prolog version
View sudoku4.pl
%% https://www.swi-prolog.org/man/clpfd.html
:- use_module(library(clpfd)).
%% ---
%% Excerpted from "Seven Languages in Seven Weeks",
%% published by The Pragmatic Bookshelf.
%% Copyrights apply to this code. It may not be used to create training material,
%% courses, books, articles, and the like. Contact us if you are in doubt.
%% We make no guarantees that this code is fit for any purpose.
%% Visit http://www.pragmaticprogrammer.com/titles/btlang for more book information.
View edit_distance_benchmarks.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@a-y-khan
a-y-khan / test_mlflow.py
Last active Dec 16, 2019
Simple, contrived example to trigger MLFlowLogger pickle bug
View test_mlflow.py
from argparse import Namespace
import itertools
import os
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.utils.data as data
import pytorch_lightning as pl
@a-y-khan
a-y-khan / graphene_hello_world.py
Last active Mar 4, 2019
Graphene Hello World
View graphene_hello_world.py
# https://gist.github.com/a-y-khan/69189c26df2dcbc8a252b02af897977d
# Super-simple example from Graphene tutorial
import graphene
from gql import gql, Client
class Query(graphene.ObjectType):
hello = graphene.String(argument=graphene.String(default_value='world'))
@a-y-khan
a-y-khan / test_ijson_parser.py
Created Jan 21, 2019
Naive parsing and output of JSON attributes to CSV.
View test_ijson_parser.py
import csv
import ijson
def test_ijson(filename):
record = {'records.item.author': None,
'records.item.author_flair_text': None,
'records.item.body': None}
parser = ijson.parse(open(filename, 'r'))
View yellowbrick_colormap3.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.