Skip to content

Instantly share code, notes, and snippets.

View tardieu's full-sized avatar

Olivier Tardieu tardieu

View GitHub Profile
@tardieu
tardieu / httpdate.swift
Last active January 26, 2017 20:49
Several ways to compose an HTTP date in Swift
import Foundation
// get current date as a series of integers
// (could be done differently...)
var theTime = time(nil)
var timeStruct = tm()
gmtime_r(&theTime, &timeStruct)
let wday = Int(timeStruct.tm_wday)
let mday = Int(timeStruct.tm_mday)
@tardieu
tardieu / unsafeString.swift
Created February 15, 2017 00:49
Unsafe String extension for Swift 3
extension String {
/// The base address of the contiguous buffer containing the String elements
/// if the String is backed by a contiguous buffer.
///
/// There is no guarantee that the String is backed by a contiguous buffer.
/// Even if it is, there is no guarantee that the buffer is writable.
public var baseAddress: UnsafeRawPointer? {
return UnsafeRawPointer(self._core._baseAddress)
}
@tardieu
tardieu / withUnsafe.swift
Last active February 21, 2017 16:12
Performance tests for unsafe String API
extension String {
/// The base address of the contiguous buffer containing the String elements
/// if the String is backed by a contiguous buffer.
///
/// There is no guarantee that the String is backed by a contiguous buffer.
/// Even if it is, there is no guarantee that the buffer is writable.
public var baseAddress: UnsafeRawPointer? {
return UnsafeRawPointer(self._core._baseAddress)
}
@tardieu
tardieu / composer.md
Last active February 19, 2018 19:55
Composer v2

Install the composer module with npm:

$ npm -g install @ibm-functions/composer@index

Create actions named condition, success, and failure as described in bootcamp/README.md#your-first-composition.

Create a file named demo_if.js:

@tardieu
tardieu / hello-world.js
Last active August 6, 2019 18:21
SolSA Hello World Example
let { Bundle, ContainerizedService } = require('solsa')
let bundle = new Bundle()
bundle.service = new ContainerizedService({
name: 'hello-world',
image: 'docker.io/ibmcom/kn-helloworld',
port: 8080
})
bundle.ingress = new bundle.service.Ingress()
module.exports = bundle
@tardieu
tardieu / hello-world.yaml
Last active August 6, 2019 18:21
YAML for SolSA Hello World Example
apiVersion: v1
kind: Service
metadata:
name: hello-world
spec:
ports:
- port: 8080
targetPort: 8080
selector:
solsa.ibm.com/pod: hello-world
@tardieu
tardieu / ingress.yaml
Last active September 6, 2019 19:04
Ingress YAML
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: hello-world
spec:
rules:
- host: hello-world.mycluster-123456.us-south.containers.appdomain.cloud
http:
paths:
- backend:
@tardieu
tardieu / topic.js
Last active September 6, 2019 19:39
SolSA Event Streams instance and topic
let { Bundle, EventStreams } = require('solsa')
let bundle = new Bundle()
bundle.kafka = new EventStreams({ name: 'kafka', plan: 'standard' })
bundle.topic = new bundle.kafka.Topic({ name: 'topic', topicName: 'MyTopic' })
module.exports = bundle
@tardieu
tardieu / topic.yaml
Last active September 6, 2019 19:40
Event Streams Topic YAML
apiVersion: ibmcloud.ibm.com/v1alpha1
kind: Topic
metadata:
name: topic
spec:
bindingFrom:
name: kafka
topicName: MyTopic
@tardieu
tardieu / source.js
Created September 6, 2019 19:58
Knative Event Source
let { Bundle, EventStreams } = require('solsa')
let bundle = new Bundle()
bundle.kafka = new EventStreams({ name: 'kafka', plan: 'standard' })
bundle.topic = new bundle.kafka.Topic({ name: 'topic', topicName: 'MyTopic' })
bundle.source = new bundle.topic.Source({ name: 'source', sink: { name: 'test-sink' } })
module.exports = bundle