Skip to content

Instantly share code, notes, and snippets.

@jheth
jheth / AuthnRequest
Last active December 31, 2015 08:39
<?xml version="1.0" encoding="UTF-8"?>
<samlp:AuthnRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
ID="alcoelhllgeljalnmneocaeebekgmboefbnaeehk"
Version="2.0"
IssueInstant="2013-12-14T17:08:02Z"
ProtocolBinding="urn:oasis:names.tc:SAML:2.0:bindings:HTTP-Redirect"
ProviderName="hostedservice.com"
AssertionConsumerServiceURL="https://www.hostedservice.com/sso/saml/acs"/>
<samlp:Response xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
ID="R3fcfe38ecf56858aed1c82e64af35a184365666b" Version="2.0"
IssueInstant="2013-12-14T17:39:06Z" Destination="https://www.hostedservice.com/sso/saml/acs"
InResponseTo="_8dc163f0-4714-0131-0e2a-20c9d04963c9">
<saml:Issuer>https://app.onelogin.com/saml/metadata/XXXXXX</saml:Issuer>
<samlp:Status>
<samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" />
</samlp:Status>
<saml:Assertion xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@jheth
jheth / gist:8030435
Created December 18, 2013 21:50
Ruby Gem Spec Parsing
# Try to load gem information from spec file. Often fails due to gemspec referencing git commands.
Dir.glob(ENV['GEM_HOME'] + "/**/*.gemspec").each do |spec|
spec = Gem::Specification::load(spec)
if spec
license_file = spec.homepage.to_s.include?("github") ? spec.homepage + "/master/blob/LICENSE" : ''
puts "#{spec.name}, #{spec.version}, #{spec.homepage}, #{spec.license}, #{license_file}"
end
end
# regex for values we care about
# Turn off the automatic pager
Pry.config.pager = false
# Make the prompt silly.
Pry.config.prompt_name = 'oh no!'
# Hit Enter to repeat last command
#Pry::Commands.command(/^$/, 'repeat last command') do
# _pry_.run_command Pry.history.to_a.last
#end
@jheth
jheth / bulk_delete_redis.sh
Created November 29, 2016 19:16
Bulk Redis Delete
redis-cli KEYS "Proposal*" | xargs redis-cli DEL
# Default 1 MB
show variables like 'max_allowed_packet'
# 10 MB
set global max_allowed_packet=10485760
@jheth
jheth / go-clean-string.go
Last active January 3, 2018 17:58
GoLang CleanString
// Hacky way to strip unicode characters.
func CleanText(text string, maxLength int) string {
if len(text) < 5 {
return ""
}
if strings.Contains(text, "\n") {
sections := strings.Split(text, "\n")
newText := sections[0]
for idx, s := range sections {
@jheth
jheth / update-from-sub-query.sql
Last active January 24, 2018 16:00
sql update from sub-query
-- great way to batch update using a sub-query in the from clause
update category set catid=100
from (
select event.catid
from event
left join category cat on event.catid = cat.catid
where cat.catid is null
limit 1000
) eventcat
where category.catid = eventcat.catid
@jheth
jheth / MarshalJSON.go
Created March 22, 2018 13:37
NullInt64 MarshalJSON
// NullInt64 is an alias for sql.NullInt64 data type
type NullInt64 sql.NullInt64
// MarshalJSON for NullInt64
func (ni *NullInt64) MarshalJSON() ([]byte, error) {
if !ni.Valid {
return []byte("null"), nil
}
return json.Marshal(ni.Int64)
^[^iIoOqQ'-]{10,17}$