Skip to content

Instantly share code, notes, and snippets.

@alexhsamuel
alexhsamuel / picklesize.py
Created September 20, 2015 21:49
pickle size efficiency for Pandas dataframes
import numpy as np
import pickle
def pickle_size(obj):
return len(pickle.dumps(obj))
def arr_size(arr):
try:
categories, codes = arr.categories, arr.codes
@alexhsamuel
alexhsamuel / bought_most.cxx
Last active September 21, 2015 19:06
template: find the customer who bought most of each product
struct Customer {
long id;
string const name;
// ...
};
struct Order {
long customer_id;
long product_id;
int quantity;

Keybase proof

I hereby claim:

  • I am alexhsamuel on github.
  • I am alexhsamuel (https://keybase.io/alexhsamuel) on keybase.
  • I have a public key ASB-6crxu0l1I_jsUPtQAh2iK3kOg2qVqL4AT7FEsl1X9wo

To claim this, I am signing this object:

@alexhsamuel
alexhsamuel / chrono-timing.cc
Last active April 11, 2016 22:39
using std::chrono to time a function, fully inlined
#include <chrono>
#include <utility>
//------------------------------------------------------------------------------
using Elapsed = double;
template<typename FN, typename ...ARGS>
inline std::pair<Elapsed, std::result_of_t<FN&&(ARGS&&...)>>
time1(
@alexhsamuel
alexhsamuel / exercise-web-crawler.go
Last active April 25, 2016 04:58
"Web Crawler" exercise from A Tour of Go (https://tour.golang.org/concurrency/10)
package main
import (
"fmt"
"sync"
)
type Fetcher interface {
// Fetch returns the body of URL and
// a slice of URLs found on that page.
@alexhsamuel
alexhsamuel / vectorize.cc
Last active April 27, 2016 14:45
AVX2 256-bit math in action!
// compile with -O3 -march=core-avx2
void
foo(
int const* __restrict__ x,
int const* __restrict__ y,
int* __restrict__ z)
{
for (int i = 0; i < 65536; ++i)
z[i] = x[i] * 2 + y[i];
@alexhsamuel
alexhsamuel / Main.java
Last active October 4, 2017 21:48
food2fork REST API example
package net.alexsamuel.recipetest;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.IOException;
import java.net.URLEncoder;

Hello!

This is a test Markdown file.

Weather app

There are a number of free APIs available with weather forecasts. Your goal is to use one to create an app that shows the weather forecast for New York.

You will have three hours to work on the assignment. At the end of this time, please submit all code, project files, etc. that you have created.

The API

The Aeris weather API is documented here.

{
"sources" : [
{
"slug" : "bbc",
"url" : "http://www.bbc.co.uk/weather/",
"title" : "BBC"
},
{
"slug" : "forecast-io",
"url" : "http://forecast.io/",