Skip to content

Instantly share code, notes, and snippets.

View Sam-Gram's full-sized avatar

Sam Graham Sam-Gram

  • Fusionware, Inc.
  • Idaho Falls, ID
View GitHub Profile

Keybase proof

I hereby claim:

  • I am Sam-Gram on github.
  • I am samgram (https://keybase.io/samgram) on keybase.
  • I have a public key whose fingerprint is C51D 6533 96DE 814D 1DEE CA3E 3D20 1342 A2A7 2CF4

To claim this, I am signing this object:

@Sam-Gram
Sam-Gram / corruptGitFix.sh
Last active May 2, 2018 17:55
How I eventually fixed a corrupted git
# All commands start in project root
# Get back corrupted objects
git fetch -p
git unpack-objects < <new clone of remote>/.git/objects/pack/pack-<hash>.pack
#.get rid of empty files if git fsck isn't working or just in general
cd .git; find . -type f -empty -delete -print
# Find problems (anything other than dangling commit/object is a problem)
@Sam-Gram
Sam-Gram / string-distance.js
Last active August 24, 2018 20:53
String distance in JavaScript
/**
GLWT(Good Luck With That) Public License
Copyright (c) Everyone, except Author
The author has absolutely no clue what the code in this project does.
It might just work or not, there is no third option.
Everyone is permitted to copy, distribute, modify, merge, sell, publish,
sublicense or whatever they want with this software but at their OWN RISK.
@Sam-Gram
Sam-Gram / memory.sh
Last active October 3, 2018 16:26
Free Memory in MB(ish) for Linux (tested on Ubuntu 16.04)
awk 'tolower($1) ~ /memfree/ {print $2/1000 " MB"}' /proc/meminfo
#GLWT(Good Luck With That) Public License
#Copyright (c) Everyone, except Author
#The author has absolutely no clue what the code in this project does.
#It might just work or not, there is no third option.
#Everyone is permitted to copy, distribute, modify, merge, sell, publish,
#sublicense or whatever they want with this software but at their OWN RISK.
# GOOD LUCK WITH THAT PUBLIC LICENSE
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION, AND MODIFICATION
#0. You just DO WHATEVER YOU WANT TO as long as you NEVER LEAVE A
@Sam-Gram
Sam-Gram / server.ps1
Created July 17, 2018 19:05
Powershell http server oneliner
# Stolen from https://gist.github.com/willurd/5720255
$Hso=New-Object Net.HttpListener;$Hso.Prefixes.Add("http://+:8000/");$Hso.Start();While ($Hso.IsListening){$HC=$Hso.GetContext();$HRes=$HC.Response;$HRes.Headers.Add("Content-Type","text/plain");$Buf=[Text.Encoding]::UTF8.GetBytes((GC (Join-Path $Pwd ($HC.Request).RawUrl)));$HRes.ContentLength64=$Buf.Length;$HRes.OutputStream.Write($Buf,0,$Buf.Length);$HRes.Close()};$Hso.Stop()
@Sam-Gram
Sam-Gram / rgFiles.sh
Created August 13, 2018 23:48
Ripgrep find files
rg -g '<something>*' --files --hidden 2>/dev/null
@Sam-Gram
Sam-Gram / string_distance.rs
Created September 25, 2018 06:30
String distance in rust, first stab.
/**
GLWT(Good Luck With That) Public License
Copyright (c) Everyone, except Author
The author has absolutely no clue what the code in this project does.
It might just work or not, there is no third option.
Everyone is permitted to copy, distribute, modify, merge, sell, publish,
sublicense or whatever they want with this software but at their OWN RISK.
GOOD LUCK WITH THAT PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION, AND MODIFICATION
0. You just DO WHATEVER YOU WANT TO as long as you NEVER LEAVE A
@Sam-Gram
Sam-Gram / whatismyip.sh
Last active October 3, 2018 16:27
Find IP Bash Tested on Ubuntu 16.04
# I put this in my .bashrc.
whatismyip ()
{
host myip.opendns.com resolver1.opendns.com | grep --color=auto 'has address' | awk '{print $4}'
}
#GLWT(Good Luck With That) Public License
#Copyright (c) Everyone, except Author
@Sam-Gram
Sam-Gram / update_background.sh
Created October 27, 2018 07:10
Background changer for gnome
#!/bin/bash
interval="1000"
file="file://$HOME/Documents/output.png"
echo $file
while true; do
window_size=`xdpyinfo | grep dimensions | awk '{ split($2,resArr,"x");print resArr[1] "," resArr[2]}'`
google-chrome --headless --disable-gpu --screenshot=output.png --virtual-time-budget=4000 --window-size=$window_size "https://www.windy.com/43.453/-111.445?42.956,-111.044,8"
gsettings set org.gnome.desktop.background picture-uri $file
@Sam-Gram
Sam-Gram / ftp.py
Last active January 15, 2019 20:42
TEMP FTP server in python
#!/usr/bin/env python
# ftpserver-cli.py
# Example use:
# sudo ./test.py --username=login --password=1234 --port=8007 --directory=$PWD
import sys
sys.path.append("/home/sam/.local/lib/python2.7/site-packages") # enter your proper path here
import argparse
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler