Skip to content

Instantly share code, notes, and snippets.

View xeoncross's full-sized avatar

David Pennington xeoncross

View GitHub Profile
@xeoncross
xeoncross / ReaderFunc.go
Created December 18, 2018 21:43 — forked from dolmen/ReaderFunc.go
Proposal to add ReaderFunc to package io
/*
https://play.golang.org/p/iWDGHj_-X_
This programs generates 32 random bytes formatted à la "hexdump -C".
It does it in just 2 lines of code using the power of the standard library
and a trick to convert a func Read([]byte) (int, error) into an io.Reader.
Inspiration: see HandlerFunc in net/http
@xeoncross
xeoncross / gist:c1b19a39c0add210d4a5d36f760f11b6
Created October 30, 2018 17:33 — forked from jonathanmoore/gist:2640302
Get the share counts from various APIs

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

@xeoncross
xeoncross / debounce.go
Last active October 23, 2018 20:28
A better debounce function for Golang that prevents duplicate calls and ensures consistent timing. This example is for a any type of input (not type safe), but it can/should be adapted to specific function signatures.
package main
import (
"fmt"
"time"
)
func main() {
f := func(args ...interface{}) {
@xeoncross
xeoncross / git_overview
Created September 26, 2018 19:16 — forked from tafkey/git_overview
Print git status of all repositories under the current folder
find . -type d -name '.git' | while read dir ; do sh -c "cd $dir/../ && echo -e \"\nGIT STATUS IN ${dir//\.git/}\" && git status -s" ; done
@xeoncross
xeoncross / README.md
Created September 5, 2018 17:30 — forked from eliquious/README.md
Concurrent Map - Golang

Readme

This is an example of a sharded map using spin locks. It is extremely fast.

Benchmarks

BenchmarkCacheSet-8          	30000000	        52.6 ns/op	       0 B/op	       0 allocs/op
BenchmarkCacheGet-8 30000000 37.7 ns/op 0 B/op 0 allocs/op
@xeoncross
xeoncross / sortByteSlice.go
Created September 5, 2018 17:11 — forked from schmohlio/sortByteSlice.go
sort byte slices in Golang without needing to fmt as string. useful for Set hashes
package main
import (
"bytes"
"log"
"sort"
)
// implement `Interface` in sort package.
type sortByteArrays [][]byte
@xeoncross
xeoncross / setup.md
Last active September 3, 2018 17:38 — forked from slamidtfyn/setup.md
My OrangePI setup
  1. OS

  2. First Login

    • find ip with: nmap -sn 192.168.0.0/24 (didn't find device with nmap, had to use router admin)
    • ssh as root: ssh root@192.168.0.91
  • login with default password: 1234
@xeoncross
xeoncross / venmo_feed.py
Created August 29, 2018 20:25 — forked from aouyang1/venmo_feed.py
pull public transactions from venmo
#!/bin/python
import sys
import os
import requests
import json
from pprint import pprint
from urllib.parse import urlparse, parse_qs
import boto3
@xeoncross
xeoncross / README.md
Created August 9, 2018 20:20 — forked from magnetikonline/README.md
Using Dnsmasq with Ubuntu 16.04LTS/14.04LTS/12.04LTS for virtual machine web application testing.

Using Dnsmasq with Ubuntu for VM web application testing

When running virtual machines under a Linux host system for testing web apps in various browsers (e.g. Internet Explorer), I found it rather tedious having to continually tweak the hosts file within each VM for the purpose of adding entries pointing back to the host machine's development web server address.

Instead the steps below will setup Dnsmasq on a Ubuntu 16.04LTS, 14.04LTS or 12.04LTS host machine for the purpose of serving both it's own DNS queries and that of virtual machine guests. Dnsmasq will parse the /etc/hosts file on your host machine where we will keep a single set of DNS entires to our test web application(s).

@xeoncross
xeoncross / translate.go
Created July 19, 2018 18:01 — forked from hvoecking/translate.go
Golang reflection: traversing arbitrary structures
// Traverses an arbitrary struct and translates all stings it encounters
//
// I haven't seen an example for reflection traversing an arbitrary struct, so
// I want to share this with you. If you encounter any bugs or want to see
// another example please comment.
//
// The MIT License (MIT)
//
// Copyright (c) 2014 Heye Vöcking
//