Skip to content

Instantly share code, notes, and snippets.

View sebsto's full-sized avatar

Sébastien Stormacq sebsto

View GitHub Profile
@sebsto
sebsto / appsync_tls_3.js
Created January 20, 2019 13:57
AppSync client creation with custom OKHTTP Client
// tm is the trust manager, code to instantiate this is skipped for brevity
// let's create our own OKHttpClient and configure it to use our custom SSLSocketFactory
val okHTTPClient = OkHttpClient.Builder().sslSocketFactory(TLSSocketFactory(), tm).build()
// Tell the builder to use our own OK HTTP client
appSyncBuilder.okHttpClient(okHTTPClient)
appSyncClient = appSyncBuilder.build()
@sebsto
sebsto / S3.py
Created May 4, 2019 12:35
Bien démarrer avec Amazon S3 et Python
import logging
import boto3
from botocore.exceptions import ClientError
def upload_file(file_name, bucket, object_name=None):
"""Upload a file to an S3 bucket
:param file_name: File to upload
:param bucket: Bucket to upload to
:param object_name: S3 object name. If not specified then file_name is used
@sebsto
sebsto / async1.js
Created June 25, 2019 08:51
Async - the ugly
function asyncWorker(callback) {
setTimeout(callback, 2000);
}
function main() {
callback = () => {
console.debug('callback !');
}
@sebsto
sebsto / async2.js
Created June 25, 2019 08:54
Async - the bad
function asyncWorker() {
return new Promise( (resolve, reject) => {
setTimeout(resolve, 2000);
});
}
function main() {
callback = () => {
@sebsto
sebsto / async3.js
Created June 25, 2019 08:57
Async - the good
async function asyncWorker() {
return new Promise( (resolve, reject) => {
setTimeout(resolve, 2000);
});
}
async function main() {
console.debug('Started');
@sebsto
sebsto / async4.js
Created June 25, 2019 09:07
Async - AWS SDK for Javascript
function updatePlayCount(your_object) {
return new Promise((resolve, reject) => {
const LAST_PLAYED_TIME = Math.round(new Date() / 1000);
var params = {
TableName: "your_table",
Key: {
"cognitoid": your_object.userId,
@sebsto
sebsto / menubar.swift
Created July 10, 2019 17:23
List MacOS MenuBar items
import Foundation
import CoreGraphics
let windowInfos = CGWindowListCopyWindowInfo(CGWindowListOption.optionOnScreenOnly, kCGNullWindowID) as! Array<CFDictionary>
for item in windowInfos {
if let dict = item as? [CFString: AnyObject] {
if ( dict[kCGWindowLayer] as! Int == 25 && dict[kCGWindowOwnerName] as! String != "SystemUIServer" ) {
print("StatusBar Item \(dict)")
}
@sebsto
sebsto / code-stack.ts
Last active October 12, 2023 13:12
CDK Create EC2 instace in private subnet. Install Nginx.
import ec2 = require('@aws-cdk/aws-ec2');
import cdk = require('@aws-cdk/core');
import { Fn, Tag, Resource } from '@aws-cdk/core';
import { AmazonLinuxImage, UserData, InstanceType } from '@aws-cdk/aws-ec2';
import { Role, ServicePrincipal, ManagedPolicy, CfnInstanceProfile } from '@aws-cdk/aws-iam'
/**
* Create my own Ec2 resource and Ec2 props as these are not yet defined in CDK
* These classes abstract low level details from CloudFormation
@sebsto
sebsto / batch-write-items.json
Created October 5, 2019 13:05
Amazon DynamoDB batch write
{
"demo-global-table": [
{
"PutRequest": {
"Item": {
"id": {"S": "0123456789"},
"firstname": {"S": "Jeff"},
"lastname": {"S": "Barr"}
}
}
@sebsto
sebsto / s3-ls.py
Created November 15, 2019 14:36
Amazon S3 - List all your buckets (aka 'ls' command)
import boto3
s3 = boto3.resource('s3')
for bucket in s3.buckets.all():
print(bucket.name)