Skip to content

Instantly share code, notes, and snippets.

View Allan-Gong's full-sized avatar

Allan Gong Allan-Gong

  • Facebook
  • Seattle, US
View GitHub Profile
@Allan-Gong
Allan-Gong / gist:c3d5a459873bb72e8f535ddbc3ce646c
Created September 27, 2024 02:42
changeset for changing a rum application name
[
{
"type": "Resource",
"resourceChange": {
"policyAction": "ReplaceAndDelete",
"action": "Modify",
"logicalResourceId": "TestAppMonitor",
"physicalResourceId": "TestAppMonitor",
"resourceType": "AWS::RUM::AppMonitor",
"replacement": "True",
@Allan-Gong
Allan-Gong / gist:eca531dc82152441383e383456ed492c
Created April 1, 2024 21:36
CloudWatchAgentServerPolicy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "CWACloudWatchServerPermissions",
"Effect": "Allow",
"Action": [
"cloudwatch:PutMetricData",
"ec2:DescribeVolumes",
"ec2:DescribeTags",
@Allan-Gong
Allan-Gong / gist:5532d2b950f148f1d83d3039db816fcb
Created April 1, 2024 21:35
CloudWatchAgentAdminPolicy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "CWACloudWatchPermissions",
"Effect": "Allow",
"Action": [
"cloudwatch:PutMetricData",
"ec2:DescribeTags",
"logs:PutLogEvents",
<script crossorigin='anonymous' src='https://dcupkcmoyuvm5.cloudfront.net/runtime-db3ced03541c6a1dba73.js'></script>
<script crossorigin='anonymous' src='https://dcupkcmoyuvm5.cloudfront.net/pages-074ae03aaa397e157edc.js'></script>
<script crossorigin='anonymous' src='https://dcupkcmoyuvm5.cloudfront.net/nodes-empty-states-image-chrome-f42fa5df0e74c8aaa91c.js'></script>
<script crossorigin='anonymous' src='https://dcupkcmoyuvm5.cloudfront.net/dialogs-678c6bdbd3b98c546e3a.js'></script>
<script crossorigin='anonymous' src='https://dcupkcmoyuvm5.cloudfront.net/jquery-lodash-3809ac86f28ed37b84b5.js'></script>
<script crossorigin='anonymous' src='https://dcupkcmoyuvm5.cloudfront.net/clouddrive-flux-adapters-1981fc80a7972ac1ec20.js'></script>
<script crossorigin='anonymous' src='https://dcupkcmoyuvm5.cloudfront.net/moment-92a69cf17837993ab7e3.js'></script>
<script crossorigin='anonymous' src='https://dcupkcmoyuvm5.cloudfront.net/react-virtualized-f223c90cce2a7c654658.js'></script>
<script crossorigin='anonymous' sr
/**
* 2. 給兩個相同長度的integer array, 分別表示從A城市到B城市每天去程和回程的票價.
* 要找出來回票價加總最便宜是多少,規定不能同天來回, 回程要在去程之後.
* 舉例: departure=[10, 8, 9, 11, 7], arrival=[8, 8, 10, 7, 9],
* 那結果是15 (departure[1] + arrival[3] = 8 + 7 = 15)
*/
public class CheapestFlights {
public int cheapeast(int[] from, int[] to) {
}
class Solution {
public int longestOnes(int[] nums, int k) {
int n = nums.length;
int countOfZero = 0;
int longest = 0;
//. s
// [0,1,1,0,0,0,1,1,1,1,0]
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
@Allan-Gong
Allan-Gong / 199.java
Created September 26, 2021 04:03
BFS template - 199
class Solution {
// Tree level-traversal
// Graph - BFS
public List<Integer> rightSideView(TreeNode root) {
if (root == null) return Collections.emptyList();
List<Integer> results = new ArrayList<>();
Deque<TreeNode> queue = new LinkedList<>();
queue.add(root);
private def logTempDiskSpace() = {
val tempDirectory = new File(System.getProperty("java.io.tmpdir"))
val tempDirectoryPath = tempDirectory.getCanonicalPath
val tempDirectorySize = FileUtils.byteCountToDisplaySize(FileUtils.sizeOfDirectory(tempDirectory))
logger.debug(s"Temp directory [$tempDirectoryPath] with size $tempDirectorySize")
tempDirectory.listFiles().toList.foreach(file => {
if (file.isDirectory) {
val directorySize = FileUtils.byteCountToDisplaySize(FileUtils.sizeOfDirectory(file))
logger.debug(s"${file.getName} - $directorySize")
// sliding[B >: A](size: Int, step: Int = 1): GroupedIterator[B]
// Returns an iterator which presents a "sliding window" view of another iterator.
// The first argument is the window size, and the second is how far to advance the window on each iteration; defaults to 1.
// Example usages:
// Returns List(List(1, 2, 3), List(2, 3, 4), List(3, 4, 5))
(1 to 5).iterator.sliding(3).toList
// Returns List(List(1, 2, 3, 4), List(4, 5))
(1 to 5).iterator.sliding(4, 3).toList
// Returns List(List(1, 2, 3, 4))