Skip to content

Instantly share code, notes, and snippets.

View dmiyakawa's full-sized avatar
🤠
Vacation in Raccoon City

Daisuke Miyakawa dmiyakawa

🤠
Vacation in Raccoon City
View GitHub Profile
@dmiyakawa
dmiyakawa / gist:4169186
Created November 29, 2012 13:46
Compress
import Data.List(group)
import Control.Arrow
solve = concatMap (uncurry (:) . (head &&& show . length)) . group
@dmiyakawa
dmiyakawa / gist:4169204
Created November 29, 2012 13:49
Compress 2
import Data.List
import Control.Arrow
-- "aaabbbbcc"
-- ["aaa", "bbbb", "cc"]
f1 :: String -> [String]
f1 str = group str
-- "aaa"
-- -> ("a", "3")
@dmiyakawa
dmiyakawa / gist:4173837
Created November 30, 2012 04:56
SAML IdP metadata example 1
<EntityDescriptor entityID="https://idp.example.com/idp/shibboleth">
<IDPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:1.1:protocol urn:mace:shibboleth:1.0 urn:oasis:names:tc:SAML:2.0:protocol">
<Extensions>
<shibmd:Scope regexp="false" xmlns:shibmd="urn:mace:shibboleth:metadata:1.0">idp.example.com</shibmd:Scope>
<mdui:UIInfo xmlns:mdui="urn:oasis:names:tc:SAML:metadata:ui">
<mdui:DisplayName xml:lang="ja">idp-example</mdui:DisplayName>
<mdui:DisplayName xml:lang="en">idp-example Inc.</mdui:DisplayName>
<mdui:Logo height="75" width="200">http://www.idp-example.co.jp/images/logo.png</mdui:Logo>
<mdui:InformationURL xml:lang="ja">http://www.idp-example.co.jp/</mdui:InformationURL>
<mdui:InformationURL xml:lang="en">http://www.idp-example.co.jp/</mdui:InformationURL>
@dmiyakawa
dmiyakawa / gist:4173843
Created November 30, 2012 04:58
Converted metadata with SimpleSAMLphp flat-file format
$metadata['https://idp.example.com/idp/shibboleth'] = array (
'name' => 'ssp_flat',
'metadata-set' => 'saml20-idp-remote',
'entityid' => 'https://idp.example.com/idp/shibboleth',
'SingleSignOnService' => array (
0 =>
array (
'Binding' => 'urn:mace:shibboleth:1.0:profiles:AuthnRequest',
'Location' => 'https://idp.example.com/idp/profile/Shibboleth/SSO',
),
@dmiyakawa
dmiyakawa / gist:4202359
Created December 4, 2012 10:04
An example of wikiconfig.py with moinmoinsaml modification
# -*- coding: iso-8859-1 -*-
# IMPORTANT! This encoding (charset) setting MUST be correct! If you live in a
# western country and you don't know that you use utf-8, you probably want to
# use iso-8859-1 (or some other iso charset). If you use utf-8 (a Unicode
# encoding) you MUST use: coding: utf-8
# That setting must match the encoding your editor uses when you modify the
# settings below. If it does not, special non-ASCII chars will be wrong.
"""
MoinMoin - Configuration for a single wiki
@dmiyakawa
dmiyakawa / gist:4202458
Created December 4, 2012 10:22
Code snnipet for moinmoinsaml with "GivenFamily" account support
name = None
given = saml_attributes.get('givenName', None)
family = saml_attributes.get('sn', None)
if given and family:
# custom flow by me.
# If both given and family names are available, combine them
# into one and treat it as a MoinMoin candidate
logging.debug('Found both given and family names')
candidate = (given[0] + family[0]).replace(' ', '')
if user.isValidName(request, candidate):
@dmiyakawa
dmiyakawa / gist:4231538
Created December 7, 2012 07:41
Encryption test (just for curiosity.. not for theoretical verification)
<html>
<head>
<title>Encryption test..</title>
</head>
<body>
<?php
// $textToEncrypt = "My super secret information.";
@dmiyakawa
dmiyakawa / adfs_init_term
Created December 26, 2012 07:36
adfs.cpp の init/term 部分のみ。 https://wiki.shibboleth.net/confluence/pages/viewpage.action?pageId=4359178 を見ると SessionInitiator, LogoutInitiator, AssertionConsumerService タグに対応して動作するようになっており、initのregisterFactory() がそれに対応している。言い換えれば、それらをフックするにはadfs.cppと同様のことをやれば良いということ。
extern "C" int ADFS_EXPORTS xmltooling_extension_init(void*)
{
SPConfig& conf=SPConfig::getConfig();
conf.SessionInitiatorManager.registerFactory("ADFS", ADFSSessionInitiatorFactory);
conf.LogoutInitiatorManager.registerFactory("ADFS", ADFSLogoutInitiatorFactory);
conf.AssertionConsumerServiceManager.registerFactory("ADFS", ADFSLogoutFactory);
conf.AssertionConsumerServiceManager.registerFactory(WSFED_NS, ADFSLogoutFactory);
#ifndef SHIBSP_LITE
SAMLConfig::getConfig().MessageDecoderManager.registerFactory(WSFED_NS, ADFSDecoderFactory);
XMLObjectBuilder::registerBuilder(xmltooling::QName(WSTRUST_NS,"RequestedSecurityToken"), new AnyElementBuilder());
@dmiyakawa
dmiyakawa / gist:5376622
Created April 13, 2013 02:27
Very simple program printing Private/Public keys using PEM encoding. Better, more comprehensive example is available from https://bitbucket.org/bumble/bumble-golang-common/src/master/key/ (not mine!)
// Almost based on
// https://bitbucket.org/bumble/bumble-golang-common/src/master/key/
package main
import "crypto/rsa"
import "crypto/rand"
import "crypto/x509"
import "encoding/pem"
import "fmt"
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
m := make(map[string]int)
for _, val := range strings.Fields(s) {