Skip to content

Instantly share code, notes, and snippets.

View iancharters's full-sized avatar

Ian Charters iancharters

  • Coalition Inc.
  • BC, Canada
View GitHub Profile
@iancharters
iancharters / column_average_bytes.sh
Last active April 10, 2024 20:36
Finds the average size in bytes of the content of the column "Body"
#!/bin/bash
# Check if a file path is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <csv_file_path>"
exit 1
fi
file_path=$1
total_size=0
@iancharters
iancharters / logging_middleware.go
Created November 3, 2023 18:00
A logging middleware that captures response, code and duration of call
package main
import (
"bytes"
"io"
"log"
"net/http"
"time"
)
package main
import (
"fmt"
)
type thing struct {
val string
}
@iancharters
iancharters / gist:9c03f42dcd0e1e085d9af19c6a8e2326
Created November 22, 2021 03:12
Demonstrating that wrapping a decorating in a decorator and only using functools wraps on the inner decorator will still preserve metadata
import time
from functools import wraps
def conditional_decorator(decorator, condition):
"""
Used to conditionally decorate a function.
"""
def wrapped_decorator(func):
function createObjectFromTypes<T>({types, data}: {types: string[]; data: T[]}) {
const sortedData = types.reduce((acc, type) => {
const typeData = data.reduce((acc, item) => {
if (item.sys.contentType.sys.id === type) {
return [...acc, item];
}
return acc;
}, []);
import React, {useState} from 'react';
import ReactDOM from 'react-dom';
import {Button} from '/component/base/Button';
export const Test = ({children, toolTip, ...props}) => {
const [toolTipStyle, setToolTipStyle] = useState({
display: 'none',
top: 0,
left: 0,
def verify_state_input(fields) do
required_fields = [:client_id, :provider, :redirect_uri, :sub]
# Determine which keys are missing from the state input and add it to our
# errors so that we can return exactly what we're missing to the client
field_errors =
required_fields
|> Enum.reduce(%{}, fn required_key, acc ->
has_key? =
defmodule ApiWeb.TestController do
use ApiWeb, :controller
alias Api.OAuth.Github
alias ApiWeb.View.TestView
# action_fallback(ApiWeb.FallbackController)
def callback(conn, %{"code" => code, "state" => _state}) do
response = Github.get_token(code)
IO.inspect(response)
defmodule Api.OAuth.Github do
use OK.Pipe
@authorize_url "https://github.com/login/oauth/authorize"
@token_url "https://github.com/login/oauth/access_token"
@api_url_base "https://api.github.com"
@base_url "http://localhost:4000"
@client_id System.get_env("GITHUB_CLIENT_ID")
@client_secret System.get_env("GITHUB_CLIENT_SECRET")
0xae2154ff601936F76FF23f4d2B0de7e4E0219b53