Skip to content

Instantly share code, notes, and snippets.

Avatar

Matt Aimonetti mattetti

View GitHub Profile
@mattetti
mattetti / multipart_upload.go
Last active Aug 12, 2022
Example of doing a multipart upload in Go (golang)
View multipart_upload.go
package main
import (
"bytes"
"fmt"
"io"
"log"
"mime/multipart"
"net/http"
"os"
@mattetti
mattetti / gist:5104790
Created Mar 7, 2013
Ruby 2.0 module prepend example
View gist:5104790
# Not our code
class Action
def start
"just do it"
end
end
# The module including our modifying code
module RubyIt
def start
View gpm.bash
#!/usr/bin/env bash
set -eu
## The Godeps file is expected to have lines like so:
#
# github.com/nu7hatch/gotrail v2.6
#
## where the first element is the import path and the second is a tag
## or commit SHA in the project.
@mattetti
mattetti / gist:1015948
Created Jun 9, 2011
some excel formulas in Ruby
View gist:1015948
module Excel
module Formulas
def pmt(rate, nper, pv, fv=0, type=0)
((-pv * pvif(rate, nper) - fv ) / ((1.0 + rate * type) * fvifa(rate, nper)))
end
def ipmt(rate, per, nper, pv, fv=0, type=0)
p = pmt(rate, nper, pv, fv, 0);
ip = -(pv * pow1p(rate, per - 1) * rate + p * pow1pm1(rate, per - 1))
(type == 0) ? ip : ip / (1 + rate)
@mattetti
mattetti / newWindowsMachine.sh
Last active Mar 17, 2022
bash script to run from WSL to setup Windows and Linux from the linux side. To run: `wget https://gist.githubusercontent.com/mattetti/9807e2a1e654a7c00bb9c13f340fc39f/raw/ -O newMachineSetup.sh` and then `bash newMachineSetup.sh`
View newWindowsMachine.sh
#!/bin/bash
export WINHOME=$(wslpath "$(wslvar USERPROFILE)")
# github username is needed to pull down the dot files
export GITHUBUSERNAME="mattetti"
# wininstall does an install using winget and checks that it went well
function wininstall {
echo "Installing $1";
cmd.exe /C winget.exe install -e $1;
@mattetti
mattetti / main.go
Created Jun 6, 2011
Go's reflection example
View main.go
package main
import(
"fmt"
"reflect"
)
func main(){
// iterate through the attributes of a Data Model instance
for name, mtype := range attributes(&Dish{}) {
View iTunes.h
/*
* iTunes.h
*/
#import <AppKit/AppKit.h>
#import <ScriptingBridge/ScriptingBridge.h>
@class iTunesPrintSettings, iTunesApplication, iTunesItem, iTunesArtwork, iTunesEncoder, iTunesEQPreset, iTunesPlaylist, iTunesAudioCDPlaylist, iTunesDevicePlaylist, iTunesLibraryPlaylist, iTunesRadioTunerPlaylist, iTunesSource, iTunesTrack, iTunesAudioCDTrack, iTunesDeviceTrack, iTunesFileTrack, iTunesSharedTrack, iTunesURLTrack, iTunesUserPlaylist, iTunesFolderPlaylist, iTunesVisual, iTunesWindow, iTunesBrowserWindow, iTunesEQWindow, iTunesPlaylistWindow;
@mattetti
mattetti / audioGenButton.cs
Created Oct 5, 2021
Unity script to generate and load an audio clip using Azure Cognitive Services
View audioGenButton.cs
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using Microsoft.CognitiveServices.Speech;
using Microsoft.CognitiveServices.Speech.Audio;
using System.IO;
using UnityEngine.Networking;
using System.Threading.Tasks;
@mattetti
mattetti / gist:3798173
Last active Sep 11, 2021
async fetching of urls using goroutines and channels
View gist:3798173
package main
import (
"fmt"
"net/http"
"time"
)
var urls = []string{
"https://splice.com/",
@mattetti
mattetti / tracepoint_middlware.rb
Created Mar 6, 2013
test middleware for Ruby 2.0 logging the method dispatches going on when a request is being handled.
View tracepoint_middlware.rb
class TracePoint
class Middleware
def initialize(app)
@app = app
end
def call(env)
stats = {}
trace = TracePoint.new(:call) do |tp|