Skip to content

Instantly share code, notes, and snippets.

View gwsu2008's full-sized avatar

Guang gwsu2008

View GitHub Profile
@gwsu2008
gwsu2008 / numpy-ma.py
Created December 30, 2019 05:17 — forked from edenau/numpy-ma.py
import math
def is_prime(n):
assert n > 1, 'Input must be larger than 1'
if n % 2 == 0 and n > 2:
return False
return all(n % i for i in range(3, int(math.sqrt(n)) + 1, 2))
arr = np.array(range(2,100))
non_prime_mask = [not is_prime(n) for n in a]
prime_arr = np.ma.MaskedArray(data=arr, mask=non_prime_mask)
score = np.array([70, 60, 50, 10, 90, 40, 80])
name = np.array(['Ada', 'Ben', 'Charlie', 'Danny', 'Eden', 'Fanny', 'George'])
sorted_name = name[np.argsort(score)] # an array of names in ascending order of their scores
print(sorted_name) # ['Danny' 'Fanny' 'Charlie' 'Ben' 'Ada' 'George' 'Eden']
original_name = sorted_name[np.argsort(np.argsort(score))]
print(original_name) # ['Ada' 'Ben' 'Charlie' 'Danny' 'Eden' 'Fanny' 'George']
%timeit name[np.argsort(score)]
@gwsu2008
gwsu2008 / Makefile
Created April 17, 2020 17:45 — forked from ryu1kn/Makefile
Encrypt/decrypt with AWS KMS using AWS cli
# How to encrypt/decrypt your text/blob secret with AWS KMS with AWS cli
KEY_ID=alias/my-key
SECRET_BLOB_PATH=fileb://my-secret-blob
SECRET_TEXT="my secret text"
ENCRYPTED_SECRET_AS_BLOB=encrypted_secret_blob
DECRYPTED_SECRET_AS_BLOB=decrypted_secret_blob # Result of decrypt-blob target
encrypt-text:
@gwsu2008
gwsu2008 / One import via join.yaml
Created May 1, 2020 20:31 — forked from jgautheron/One import via join.yaml
Fn::ImportValue from other stacks
Tags:
- Key: Name
Value:
!Join ['_', [ ec2, "Fn::ImportValue" : {"Fn::Sub":'${BaseStackName}-Environment'}, test2]]
#This will create a name tag with value: ec2_<yourValueFromOtherStack>_test2
@gwsu2008
gwsu2008 / diff-jq.md
Created June 14, 2020 15:44 — forked from ipan/diff-jq.md
compare two JSONs with jq #json #jq
# This is a really old post, in the comments (and stackoverflow too) you'll find better solutions.
def find(key, dictionary):
for k, v in dictionary.iteritems():
if k == key:
yield v
elif isinstance(v, dict):
for result in find(key, v):
yield result
elif isinstance(v, list):
@gwsu2008
gwsu2008 / s3_full_delete.py
Created October 9, 2021 22:56 — forked from vsx-gh/s3_full_delete.py
Remove completely S3 objects that have delete markers
#!/usr/bin/env python3
'''
Program: s3_full_delete.py
Author: https://github.com/vsx-gh
Created: 20170920
Program finds S3 objects with delete markers and deletes all versions
of those objects.
@gwsu2008
gwsu2008 / envelope_encryption_kms_boto_pycrypto.md
Created November 17, 2021 16:35 — forked from pmp/envelope_encryption_kms_boto_pycrypto.md
Envelope Encryption using AWS KMS, Python Boto, and PyCrypto.

If you use Amazon AWS for nearly anything, then you are probably familiar with KMS, the Amazon Key Management Service.

KMS is a service which allows API-level access to cryptographic primitives without the expense and complexity of a full-fledged HSM or CloudHSM implementation. There are trade-offs in that the key material does reside on servers rather than tamper-proof devices, but these risks should be acceptable to a wide range of customers based on the care Amazon has put into the product. You should perform your own diligence on whether KMS is appropriate for your environment. If the security profile is not adequate, you should consider a stronger product such as CloudHSM or managing your own HSM solutions.

The goal here is to provide some introductory code on how to perform envelope encrypt a message using the AWS KMS API.

KMS allows you to encrypt messages of up to 4kb in size directly using the encrypt()/decrypt() API. To exceed these limitations, you must use a technique called "envelope encryptio

@gwsu2008
gwsu2008 / Jenkins+Script+Console.md
Created February 19, 2022 19:52 — forked from mubbashir/Jenkins+Script+Console.md
jenkins groovy scripts collection.
@gwsu2008
gwsu2008 / remove-git-lfs.md
Created August 16, 2022 21:28 — forked from everttrollip/remove-git-lfs.md
Removing git lfs from (any) repository

So, it has been an interesting journey, but time to remove git-lfs. Here follows a summary of the approach I used to safely remove git-lfs,

  • commit & push everything
  • create a branch, something like fix/remove-lfs
  • remove hooks git lfs uninstall
  • remove lfs stuff from .gitattributes (open file, delete content - don't delete the file!)
  • list all lfs files, git lfs ls-files
  • run git rm --cached for each file
    • if your list is big, copy the contents into a file.txt
  • make sure you remove the number and asterik on each line, you only want the paths to the files