Skip to content

Instantly share code, notes, and snippets.

$SomeFunction = {
param(
[string]$Name
)
return 'Hi ' + $Name + '!'
}
$Somefunction.Invoke("Jacob")
# Hi Jacob!
@jakobii
jakobii / impl_rust_distplay_example.rs
Last active February 25, 2019 07:17
implement fmt::Display on a struct in Rust
use std::fmt;
// IPv4 struct is just a tuple of u8's.
// just an arbitrary, but realistic example...
struct IPv4(u8, u8, u8, u8);
// declare the impl block for out IPv4 struct.
impl fmt::Display for IPv4 {
// this is the function signature the fmt::distplay trait is looking for.
// https://doc.rust-lang.org/std/fmt/trait.Display.html
@jakobii
jakobii / Install_ubuntu_server_kiosk.md
Last active March 1, 2019 23:40
Temp User On Ubuntu 18.04 (still in the works!)

Minimal ubuntu server kiosk install

sudo apt-get install --no-install-recommends ubuntu-desktop
@jakobii
jakobii / CSharpInPowershell.ps1
Last active February 28, 2019 04:52
Embed C# In Powershell And Define Custom Interfaces!
# here is our custom interface. hopefully powershell will support creating
# interfaces natively soon. this is a simple example and is not ment to
# teach you c# syntax. sufice it to say an interface is a *contract*. an
# interface defines what methods and properties a class should have.
# interfaces allow you to contrain function parameters to only type that
# fullfill the *contract*. this is illistrated in the code below.
$CSharpCode = @"
public interface IFoo
{
void Bar();
# variables
DISTRIB_CODENAME = bionic
cert_dir = /etc/ssl/certs/
# install
# https://rethinkdb.com/docs/install/ubuntu/
source /etc/lsb-release && echo "deb https://download.rethinkdb.com/apt $DISTRIB_CODENAME main" | sudo tee /etc/apt/sources.list.d/rethinkdb.list
wget -qO- https://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add -
sudo apt-get update
sudo apt-get install rethinkdb
package main
import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"log"
"os"
package main
import (
"database/sql"
"encoding/json"
"fmt"
"log"
_ "github.com/denisenkom/go-mssqldb"
)
@jakobii
jakobii / postgres_map_fks.md
Last active November 14, 2019 20:47
Map FKs in Postgres

Table constraints can include multiple columns. The trick to getting this right is to join each column by their constraint ordinal positions. If you don't join correctly your script will blow up with duplicate rows 😥 whenever a table has multiple columns in a unique constraint.

Table Notes

This may be helpful in understanding what these tables do.

information_schema.table_constraints

  • lists all table constraints
  • explains constraint types
@jakobii
jakobii / gzip_http_response.go
Last active November 14, 2019 21:15
gzip golang http responses
//https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
func writeOptimizedHttpResponse(w http.ResponseWriter, r *http.Request, b []byte, contentType string) {
w.Header().Set("Content-Type", contentType)
encodings := r.Header.Get("Accept-Encoding")
switch {
case strings.Contains(encodings, "gzip"):
w.Header().Set("Content-Encoding", "gzip")
@jakobii
jakobii / run_task_on_remote_servers_in_parallel.ps1
Last active January 7, 2020 20:07
Remote PSSession Tasks
# This is a scriptblock that will be invoked on the remote computer. This is
# just dummy code that gets the computers hostname from the global built in
# eniorment variable $env.
$RemoteTask = {
param(
[datetime]$Start
)
# pause remote script execition until the specified start time.
# you can use this to loosely sync jobs execution.