Skip to content

Instantly share code, notes, and snippets.

View malcolmgreaves's full-sized avatar

Malcolm Greaves malcolmgreaves

View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@malcolmgreaves
malcolmgreaves / val_max.scala
Last active February 23, 2018 04:20
Generic maximum function (max) with float-value-transforming typeclass (Val).
case class Scored[T](item: T, value: Double)
trait Val[-A] {
def valueOf(a: A): Double
}
object Val {
def apply[T: Val]: Val[T] =
implicitly[Val[T]]
@outofcoffee
outofcoffee / find-ecr-image.sh
Last active November 27, 2025 20:31
Check if Docker image exists with tag in AWS ECR
#!/usr/bin/env bash
# Example:
# ./find-ecr-image.sh foo/bar mytag
if [[ $# -lt 2 ]]; then
echo "Usage: $( basename $0 ) <repository-name> <image-tag>"
exit 1
fi
IMAGE_META="$( aws ecr describe-images --repository-name=$1 --image-ids=imageTag=$2 2> /dev/null )"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cbaziotis
cbaziotis / SelfAttention.py
Created April 21, 2018 17:31
SelfAttention implementation in PyTorch
class SelfAttention(nn.Module):
def __init__(self, attention_size, batch_first=False, non_linearity="tanh"):
super(SelfAttention, self).__init__()
self.batch_first = batch_first
self.attention_weights = Parameter(torch.FloatTensor(attention_size))
self.softmax = nn.Softmax(dim=-1)
if non_linearity == "relu":
self.non_linearity = nn.ReLU()
@malcolmgreaves
malcolmgreaves / download.sh
Created April 24, 2018 20:41
Bash function for a better CLI remote file download experience.
#!/bin/bash
# Bash function to download a file with wget, showing a progress bar and enables
# re-downloading if interrupted. Also can automatically determine filename from
# supplied URL or override from command line.
# First argument is URL.
# Second optional argument is filename.
download () {
local URL="$1"
local FI="$2"
@HarshTrivedi
HarshTrivedi / pad_packed_demo.py
Last active November 7, 2025 15:47 — forked from Tushar-N/pad_packed_demo.py
Minimal tutorial on packing (pack_padded_sequence) and unpacking (pad_packed_sequence) sequences in pytorch.
import torch
from torch import LongTensor
from torch.nn import Embedding, LSTM
from torch.autograd import Variable
from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
## We want to run LSTM on a batch of 3 character sequences ['long_str', 'tiny', 'medium']
#
# Step 1: Construct Vocabulary
# Step 2: Load indexed data (list of instances, where each instance is list of character indices)
@stevenhao
stevenhao / mode-presto-linter.js
Last active March 28, 2020 04:38
Lint prestodb sql in mode analytic's web editor
// ==UserScript==
// @name PrestoDB Linter v0.1.3
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author Steven Hao
// @match https://modeanalytics.com/editor/*
// @grant none
// ==/UserScript==
@mollymerp
mollymerp / sshfs-gcp-instance-osx.md
Last active August 4, 2025 08:07
How to mount a GCP compute instance filesystem locally using `sshfs` on MacOS

How to mount a GCP compute instance filesystem locally using sshfs

This guide assumes that:

  • you already have an instance set up on GCP that you want to mount locally
  • the GCP CLI (gcloud) is installed on your local machine
  • you have authenticated locally to your google account gcloud auth login
  1. make sure your gcloud config is correct for the instance you're trying to access:
import torch
from torch_geometric.data import InMemoryDataset
class MyOwnDataset(InMemoryDataset):
def __init__(self, root, transform=None, pre_transform=None):
super(MyOwnDataset, self).__init__(root, transform, pre_transform)
self.data, self.slices = torch.load(self.processed_paths[0])
@property