Skip to content

Instantly share code, notes, and snippets.

View Greyeye's full-sized avatar

James Hong Greyeye

  • Queensland, Australia
View GitHub Profile
@Greyeye
Greyeye / dynamo_stream_event_trigger.go
Created August 29, 2022 22:52
dynamoDB stream event trigger handling code
func handler(ctx context.Context, ev events.S3Event) {
// need to handle PUT, DELETE, UPDATE, separately
for _, record := range ev.Records {
switch record.EventName {
case "INSERT":
fmt.Printf("%+v\n", record)
var rr localTypes.ActivityEventsTable
UnmarshalStreamImage(record.Change.NewImage, rr)
@Greyeye
Greyeye / CustomController.cls
Last active December 13, 2020 22:29
salesforce remote api call template
public without sharing class CustomController {
// this value cannot be read inside the testing, make sure you insert temporary value
public static final String endpoint = Custom_Setting__c.getOrgDefaults().custom_endpoint__c;
public static String getAuthHeader() {
Auth.JWT jwt = new Auth.JWT();
jwt.setSub(UserInfo.getUserId());
Map<String, String> claims = new Map<String, String>();
@Greyeye
Greyeye / samplecaller.go
Last active February 18, 2020 22:44
aws secretsmanager using aws-sdk-go v1.6
// this is a mock code, will not compile
func getToken(ctx context.Context) (string, error) {
secretsmanagerwrapper.NewSecretsManager(context)
xray.AWS(secretsmanagerwrapper.Client())
var token
token = secretsmanagerwrapper.GetSecrets(strings.Replace(c.Host(), "-", "", -1))
if token == "" {
return nil, errors.New("failed to get token")
}
return token, nil
@Greyeye
Greyeye / dumpR53.py
Last active December 5, 2018 01:49
# dump r53 records to local console. - you need boto3
import boto3
def getZone(marker):
client = boto3.client('route53')
# Get list of zones
if marker != "":
response = client.list_hosted_zones(Marker=marker)
else:
response = client.list_hosted_zones()
@Greyeye
Greyeye / ec2_windows_bootstrap.yml
Last active April 29, 2021 22:53
ansible ec2 bootstrap for windows serverit boots up AMI with MSSQL 2014 Express and install some basic tools like 7zip, notepad++tested with Ansible 2.0.2 on ubuntu 14.04 LTS~/.aws/credentials file is required for boto File Contents ==== ./ansible/ec2_windows_bootstrap.yml ./ansible/hosts ./ansible/group_vars/windows.yml to run ===== ./ansible/>…
---
- name: Provision an EC2 Instance
hosts: local
connection: local
gather_facts: False
tags: provisioning
# Necessary Variables for creating/provisioning the EC2 Instance
vars:
instance_type: t2.small
group_id: ['sg-xxx','sg-xxx']
@Greyeye
Greyeye / findreplication.sql
Created February 5, 2016 00:55
find list of replication articles from distribution database (tested on mssql 2012/2014 standard)
SELECT
P.[publication] AS [Publication Name]
,A.[publisher_db] AS [Database Name]
,A.[article] AS [Article Name]
,A.[source_owner] AS [Schema]
,A.[source_object] AS [Table]
FROM
[distribution].[dbo].[MSarticles] AS A
INNER JOIN [distribution].[dbo].[MSpublications] AS P
ON (A.[publication_id] = P.[publication_id])
@Greyeye
Greyeye / checkpermission.ps1
Created June 19, 2014 00:15
get custom non inherited permission for a target folder/path
Param(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$targetPath
)
$SharedFolders = get-childitem -recurse -path $targetPath |where {$_.Attributes -eq 'Directory'}
foreach($SharedFolder in $SharedFolders)
{
@Greyeye
Greyeye / uitableviewcontroler-sample.swift
Created June 7, 2014 01:37
prepareforsegue usecase (subclass UITableViewController) written in Swift
//
// JamesTableViewController.swift
// swiftTest
//
// Created by James Hong on 6/06/2014.
// Copyright (c) 2014 James Hong. All rights reserved.
//
import UIKit
declare @kill varchar(8000) = '';
select @kill=@kill+'kill '+convert(varchar(5),spid)+';'
from master..sysprocesses
where dbid=db_id('MyDB');
print @kill;
exec (@kill);
SELECT
'create login [' + p.name + '] ' +
case when p.type in('U','G') then 'from windows ' else '' end +
'with ' +
case when p.type = 'S' then 'password = ' + master.sys.fn_varbintohexstr(l.password_hash) + ' hashed, ' +
'sid = ' + master.sys.fn_varbintohexstr(l.sid) +
', check_expiration = ' + case when l.is_expiration_checked > 0 then 'ON, ' else 'OFF, ' end +
'check_policy = ' + case when l.is_policy_checked > 0 then 'ON, ' else 'OFF, ' end +
case when l.credential_id > 0 then 'credential = ' + c.name + ', ' else '' end
else '' end +