Skip to content

Instantly share code, notes, and snippets.

View protosam's full-sized avatar
🎉
just building on k8s

Sam protosam

🎉
just building on k8s
  • San Antonio, TX
View GitHub Profile
@protosam
protosam / Why JS!??.js
Created June 16, 2017 01:08
Seems like I found a law of programming JS refuses to violate.
function whatever(){
this = function(){ console.log('whatever is no redefined'); }
}
@protosam
protosam / sougly.js
Created June 16, 2017 05:10
It can be better...
Object.prototype.defer = [];
Object.prototype.defertpl = function(vars_here){
try {
code_here
} finally {
for(i=0;i<this.defer.length;i++){
this.defer[i]();
}
@protosam
protosam / defer.js
Created June 16, 2017 06:16
A real solution for deferred code in javascript.
Object.prototype.deferq = [];
Object.prototype.defertpl = function(vars_here){
try {
code_here
} finally {
for(i=0;i<this.deferq.length;i++){
@protosam
protosam / nacl_output.txt
Created June 18, 2017 18:47
NaCL fails on Chrome OS 57 on Samsung Chromebook Plus 2017 model
Loading NaCl module.
Loaded elf_loader_arm.nexe [193 KiB]
Performing initial devenv setup
===> Installing core packages
Updating NaCl repository catalogue...
Repository NaCl contains no repodata table, need to re-create database
[0/0 KiB 100%] Done.
[13/13 KiB 100%] Done.
pkg: sqlite error executing CREATE TABLE packages (id INTEGER PRIMARY KEY,origin TEXT,name TEXT NOT NULL,version TEXT NOT NULL,comment TEXT NOT NULL,desc TEXT NOT NULL,osversion TEXT,arch TEXT NOT NULL,maintainer TEXT NOT NULL,www TEXT,prefix TEXT NOT NULL,pkgsize INTEGER NOT NULL,flatsize INTEGER NOT NULL,licenselogic INTEGER NOT NULL,cksum TEXT NOT NULL,path TEXT NOT NULL,pkg_format_version INTEGER,manifestdigest TEXT NULL,olddigest TEXT NULL,dep_formula TEXT NULL);CREATE TABLE deps (origin TEXT,name TEXT,version TEXT,package_id INTEGER REFERENCES packages(id) ON DELETE CASCADE ON UPDATE CASCADE,UNIQUE(package_id, name));CREATE TABLE categories (id IN
@protosam
protosam / bitwise ops.js
Created July 5, 2017 19:04
Setting Bits!
/* Produces byte sequence 0110 0000 */
var flags = 32 + 64;
console.log(flags);
/* Ensures that the _ is set to 1 in _XXX XXXX */
flags |= 128;
console.log(flags);
/* 3 Methods for ensuring bit _XXX XXXX is 0 */
@protosam
protosam / multiple-cookies.js
Last active July 12, 2017 18:48
Node HTTP Multiple Set-Cookie headers
const STATUS_CODES = require('http').STATUS_CODES;
/* Send raw headers function */
http.ServerResponse.prototype.sendRawHeader = function(name, value){
if(!this._headerSent){
this.connection.write(['HTTP/1.1', this.statusCode, STATUS_CODES[this.statusCode], '\r\n'].join(' '));
}
this.connection.write([ [name, ':'].join(''), [value, '\r\n'].join('') ].join(' '));
}
// Seriously, why you do this crypto?!?!?!?!?
package main
import (
"strings"
"fmt"
"golang.org/x/crypto/ed25519"
)
@protosam
protosam / DH_KEX_Example.js
Created September 8, 2017 01:51
Example of the Diffee Hellman Key Exchange Algorithm with Annotations.
/* The Diffie Hellman Key Exchange - Explained Again, with code
-------------------------------------------------------------------------------
The Diffie Hellman Key Exchange is commonly explained like so:
Step 1. Alice and Bob agree on a large prime number "P" and a primitive root of that, "G"
Step 2. Alice and Bob choose a large random number to compute against "p" and "g"
Alice choses a large random number "x" creates "A" below to send Bob
A=G^x % P
Bob choses a large random number "y" creates "B" below to send Alice
@protosam
protosam / xhash.go
Created September 19, 2017 13:59
searching for that GPU/ASIC hater hash....
package main
import (
"fmt"
"time"
"bytes"
"errors"
"golang.org/x/crypto/sha3"
"runtime"
@protosam
protosam / Explained.md
Created September 19, 2017 23:58
An example of private code

I want to keep some code private due to licensing, but everything I create on top of it, I want to make that open sauce for everyone. I have done so with the following files setup.

This is the app I am making for my company with the licensed software or whatever. $GOPATH/github.com/protosam/myapp/main.go

My company licenses code from these private-api guys or something. Whatever, their crud can live in this lonely repo. I need to build with this FUD-ware at some point, because I wamt to be paid. $GOPATH/github.com/protosam/private-api-extras/extras.go

The public-api repo is stuff I made for the app that I'm allowed to sauce out with whatever license. The extras.go file has a build flag of +build private. This will make it not be included during a normal build. In there I will place wrapper functions for capitolism-api cough Ahem. I mean private-api. $GOPATH/github.com/protosam/public-api/myapi.go