Skip to content

Instantly share code, notes, and snippets.

View sebsto's full-sized avatar

Sébastien Stormacq sebsto

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / appsync_tls_2.js
Created January 20, 2019 13:55
appsync client creation by default
// initialize the AppSync client
val appSyncClient = AWSAppSyncClient.builder()
.context(applicationContext)
.awsConfiguration(AWSConfiguration(applicationContext))
.credentialsProvider(credentialsProvider)
.build()
@sebsto
sebsto / appsync_tls_1.sh
Created January 20, 2019 13:54
App Sync NMAP TLS
$ nmap --script ssl-enum-ciphers <your_appsync_id>.appsync-api.eu-west-1.amazonaws.com
Starting Nmap 7.70 ( https://nmap.org ) at 2018-12-23 14:35 GMT
Nmap scan report for d7...33q.appsync-api.eu-west-1.amazonaws.com (13.xx.xx.43)
Host is up (0.033s latency).
Other addresses for d7...33q.appsync-api.eu-west-1.amazonaws.com (not scanned): 13.xx.xx.xx 13.xx.xx.xx 13.xx.xx.xx
rDNS record for 13.xx.xx.43: server-13-xx-xx-43.lhr62.r.cloudfront.net
Not shown: 998 filtered ports
PORT STATE SERVICE
80/tcp open http
@sebsto
sebsto / lwa_blog_2.js
Created January 20, 2019 13:41
call LWA profile from alexa skill
const HelloWorldIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest' && handlerInput.requestEnvelope.request.intent.name === 'HelloWorldIntent';
},
async handle(handlerInput) {
const {
accessToken
} = handlerInput.requestEnvelope.context.System.user;
let speechText = '';
if (!accessToken) {