Skip to content

Instantly share code, notes, and snippets.

View rohanthewiz's full-sized avatar

Rohan Allison rohanthewiz

  • Texas
View GitHub Profile
@rohanthewiz
rohanthewiz / struct_tag_manipulation
Created November 12, 2020 06:21
JSON Marshal based on custom struct tags
package main
import (
"encoding/json"
"fmt"
"reflect"
)
type User struct {
Username string `json:"user" db:"username"`
@rohanthewiz
rohanthewiz / scp_copy.go
Created February 22, 2020 18:06
Copy files to a secure server
package main
import (
"fmt"
"github.com/bramvdbogaerde/go-scp"
"github.com/bramvdbogaerde/go-scp/auth"
"golang.org/x/crypto/ssh"
"os"
)
@rohanthewiz
rohanthewiz / httpToHtttpsRedirector.go
Created February 18, 2019 17:07
Simple HTTP to HTTPS redirector using the Golang standard library.
// Standalone Http to Https redirector
// Credit: https://gist.github.com/d-schmidt/587ceec34ce1334a5e60
package main
import (
"fmt"
"log"
"net/http"
)
@rohanthewiz
rohanthewiz / htm-index.html
Created November 24, 2018 20:50
HTML templates with htm and no other lib/framework requirement
<!DOCTYPE html>
<html lang="en">
<title>htm Demo</title>
<script type="module">
import { html, Component, render } from 'https://unpkg.com/htm/preact/standalone.mjs';
class App extends Component {
constructor() {
super();
this.Pi = 3.1416;
@rohanthewiz
rohanthewiz / dynamic_form.html
Created September 16, 2017 14:54
jQuery Dynamic form elements with Add, Remove, Move Up, Move Down, and Serialize
<html>
<head>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="js/jquery.serialize-object.min.js"></script>
<style>
* box-sizing {border-box}
body {background-color: tan}
.module {margin: 2px; padding-bottom: 0.3rem}
</style>
</head>
@rohanthewiz
rohanthewiz / go_concurrency_pattern.go
Last active April 12, 2017 22:06
A Pattern for concurrency using Wait Groups and Buffered Channels
// A Concurrency Pattern using Wait Groups and Buffered Channels
package main
import (
"time"
"fmt"
"sync"
)
// Synopsis
@rohanthewiz
rohanthewiz / main.go
Created March 16, 2017 17:44
Golang: Sum, sort, and print values by User from data given in a file
package main
import (
"os"
"fmt"
"io/ioutil"
"strings"
"regexp"
"strconv"
"sort"
@rohanthewiz
rohanthewiz / scratch_2.go
Created March 16, 2017 17:30
Split and trim a string containing any combination of tabs and spaces into trimmed words
ackage main
import (
"fmt"
"strings"
)
func main() {
str := "When not ok\t, val\tis 0"
fmt.Printf("%q\n", SplitAndTrim(str))
@rohanthewiz
rohanthewiz / xmlparser_conversion.go
Created March 2, 2017 19:52
Converting from iso-8859-1 to utf-8
package xmlparser
import (
"os"
"golang.org/x/text/encoding/charmap"
"log"
"bytes"
"io"
"strings"
)
# A Pattern for Custom Exception types
module Orders
class OrdersError < StandardError; end
class OrdersLineItemError < OrdersError
def message
'There was a line item error.'
end
end