Skip to content

Instantly share code, notes, and snippets.

View sgml's full-sized avatar

psweatte sgml

View GitHub Profile
@sgml
sgml / gist:374addfdd5c3a09ffc2cf22147b1c9ea
Created August 22, 2020 20:30 — forked from sirleech/gist:2660189
Python Read JSON from HTTP Request of URL
# Load Json into a Python object
import urllib2
import json
req = urllib2.Request("http://localhost:81/sensors/temperature.json")
opener = urllib2.build_opener()
f = opener.open(req)
json = json.loads(f.read())
print json
print json['unit']
@sgml
sgml / fluent.py
Created April 14, 2020 04:08 — forked from thinkingserious/fluent.py
Fluent Interface in Python Using Method Chaining and Reflection
class Fluent:
def __init__(self, cache=None):
self._cache = cache or []
# Build the cache, and handle special cases
def _(self, name):
# Enables method chaining
return Fluent(self._cache+[name])
# Final method call
@sgml
sgml / shibb-cas-get.sh
Created April 1, 2020 23:28 — forked from olberger/shibb-cas-get.sh
Connection to a web app protected via Shibboleth with curl
#!/bin/sh
#set -x
# Usage: shibb-cas-get.sh {username} {password} # If you have any errors try removing the redirects to get more information
# The service to be called, and a url-encoded version (the url encoding isn't perfect, if you're encoding complex stuff you may wish to replace with a different method)
DEST=https://myapp.example.com/
SP=https://myapp.example.com/index.php
IDP="https://myidp.example.com/idp/shibboleth&btn_sso=SSOok"
@sgml
sgml / SSOByPasser.ksh
Created April 1, 2020 23:28 — forked from getkub/SSOByPasser.ksh
CURL snippet to do commands on SSO (Siteminder etc) protected systems
#!/usr/bin/ksh
#################################################################################
#
# CURL snippet to do commands on SSO (Siteminder etc) protected systems
# This script will set cookies in one server
# Copies the cookie information into another server
# Imports the cookie information to maintain seemless CURL commands
#
#################################################################################
page_name="ABC_Test"
@sgml
sgml / gist:0a853af19a1e8004dc10576b7f5e9672
Created March 16, 2020 21:21
Git Editor Toolbar Accesskey Binding
document.querySelector("#function-ul").setAttribute("accesskey","B")
@sgml
sgml / clicker.js
Created March 14, 2020 13:19
Gamestop 2K20
var clicker = window.setInterval(() => $(".show-more .text-center button").click(), 5000)
@sgml
sgml / who-is-driving-refactor.html
Created November 29, 2019 12:33 — forked from cferdinandi/who-is-driving-refactor.html
A refactor of the vanilla JS Who's Driving app.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Who should drive?</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Styles -->
<style type="text/css">
var x = 2;
var y = 8;
var a = function(b) { return function(c) { return x + y + Math.abs(b) + c; } };
// Statement will go here
Object.defineProperty(Math, 'random', {get() { return function(){ return 0; }}})
var fn = a(x);
x = 4;
console.log(fn(Math.random() * 10));
@sgml
sgml / AutoSpy.js
Created January 18, 2019 03:02
AutoSpy
var spy = 'window.releaseEvents()'.replace(/^/,"spyOn(").replace(/\.([a-zA-Z]+)/, ", '$1'").replace(/[(][)]+$/,')');
var expect = 'window.releaseEvents()'.replace(/^/, "expect('").replace(/[(][)]+/, '').replace(/$/,"').toHaveBeenCalled()")
console.log('spy: ' + spy);
console.log('expect: ' + expect);
@sgml
sgml / XHRMock.js
Created January 17, 2019 21:26
XHR Mock
XMLHttpRequest.prototype.send = function(){return this.toString()}
var foo = new XMLHttpRequest;
foo.open('get','data:text/html,<html><p>hi</p></html>');
foo.send();