Skip to content

Instantly share code, notes, and snippets.

View IanCal's full-sized avatar

Ian Calvert IanCal

  • Red Bird Data
  • Wirral
View GitHub Profile
@IanCal
IanCal / N-Queens.hs
Created February 18, 2012 10:16
A closed form solution for n-queens, from "Explicit Solutions to the N-Queens Problem for all N"
type Queen = (Int,Int)
solveNot6kplus2 :: Int -> [Queen]
solveNot6kplus2 n = firstHalf ++ secondHalf
where
firstHalf = [(j, 2 * j) | j <- range]
secondHalf = [(n `div` 2 + j, 2 * j - 1) | j <- range]
range = [1 .. n `div` 2]
solveNot6k :: Int -> [Queen]
@IanCal
IanCal / includethis.html
Created August 31, 2013 13:47
A simple inclusion approach
<!doctype html>
<head>
</head>
<body>
<section name="anchor1">
I am the INCLUDED THING
<section name="anchorsub">
I am a teeny tiny inclusion
</section>
</section>
@IanCal
IanCal / Dockerfile
Created February 6, 2015 11:34
Elasticsearch plugins and docker
FROM dockerfile/elasticsearch
RUN mkdir /elasticsearch/plugins
ADD elasticsearch.yml /elasticsearch/config/elasticsearch.yml
RUN ["/elasticsearch/bin/plugin", "--install", "mobz/elasticsearch-head"]
@IanCal
IanCal / monty_hall_variations.py
Last active December 29, 2016 00:16
Monty hall variations in strategy
from random import randint, shuffle
from collections import Counter
DOORS = 3
EXPERIMENTS = 1000
def get_doors():
doors = [True] + [False] * (DOORS - 1)
shuffle(doors)
return doors
@IanCal
IanCal / keybase.md
Created February 12, 2018 14:01
Keybase Proof

Keybase proof

I hereby claim:

  • I am iancal on github.
  • I am iancal (https://keybase.io/iancal) on keybase.
  • I have a public key ASDqDUUQp5o9mLTRp9oUwU1_XKEziIE1rnORdtAgHteCbAo

To claim this, I am signing this object:

@IanCal
IanCal / test_case.sh
Created February 13, 2019 13:13
A minimal example of DVC not using the cache
#!/bin/bash
set -ex
rm -rf test_example
mkdir test_example
cd test_example
echo "Setup DVC"
dvc init --no-scm
@IanCal
IanCal / lru_mutable_results.py
Created May 15, 2019 10:59
Be careful with lru_cache in python
from functools import lru_cache
@lru_cache(1)
def cached():
return ["Do cached entries safely return the same thing?"]
def uncached():
return ["Do cached entries safely return the same thing?"]
import streamlit as st
import streamlit.ReportThread as ReportThread
from streamlit.server.Server import Server
import pandas as pd
import json
import time
def trigger_rerun():
ctx = ReportThread.get_report_ctx()
import streamlit as st
import streamlit.ReportThread as ReportThread
from streamlit.server.Server import Server
import pandas as pd
import json
import time
def trigger_rerun():
ctx = ReportThread.get_report_ctx()
from pyarrow import csv
import pyarrow.parquet as pq
table = csv.read_csv("BasicCompanyDataAsOneFile-2022-09-01.csv")
sorted_table = table.sort_by([("CompanyName", "ascending")])
pq.write_table(sorted_table, "basic_company_data_sorted.parquet")