Skip to content

Instantly share code, notes, and snippets.

View xchehub's full-sized avatar
:octocat:

XC xchehub

:octocat:
View GitHub Profile
@piruin
piruin / DrawableCompat.kt
Last active May 3, 2023 13:09
Kotlin Extension for set/get compound Drawable to TextView/EditText/Button as property
/*
* Copyright 2017 Piruin Panichphol
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@iMilnb
iMilnb / README.md
Last active January 18, 2024 08:08
AWS Terraform configuration: Stream CloudWatch Logs to ElasticSearch

Rationale

This snippet is a sample showing how to implement CloudWatch Logs streaming to ElasticSearch using terraform. I wrote this gist because I didn't found a clear, end-to-end example on how to achieve this task. In particular, I understood the resource "aws_lambda_permission" "cloudwatch_allow" part by reading a couple of bug reports plus this stackoverflow post.

The js file is actually the Lambda function automatically created by AWS when creating this pipeline through the web console. I only added a endpoint variable handling so it is configurable from terraform.

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

@Ron3
Ron3 / History|-104b39d1|entries.json
Last active May 21, 2022 09:59
AWS Lambda初触
{"version":1,"resource":"file:///Users/ron/Documents/Work/Github/WastedLand_Unity/Assets/Code/BPGames/BPMono/BPMainController.cs","entries":[{"id":"asRE.cs","timestamp":1653017452369},{"id":"1N1A.cs","timestamp":1653017490920},{"id":"ZcIB.cs","timestamp":1653017517999},{"id":"1sWI.cs","timestamp":1653018848615},{"id":"b2y6.cs","timestamp":1653033123307},{"id":"p0fY.cs","timestamp":1653033276547},{"id":"SurA.cs","timestamp":1653033301622},{"id":"8aiu.cs","timestamp":1653033472606},{"id":"4qe9.cs","timestamp":1653038794506},{"id":"m05x.cs","timestamp":1653038809996},{"id":"8dkr.cs","timestamp":1653038832762},{"id":"xxRB.cs","timestamp":1653039127616},{"id":"1IX0.cs","timestamp":1653040123957}]}
@5agado
5agado / Pandas and Seaborn.ipynb
Created February 20, 2017 13:33
Data Manipulation and Visualization with Pandas and Seaborn — A Practical Introduction
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mda590
mda590 / boto3_listinstances_example.py
Last active April 30, 2024 05:07
Example using boto3 to list running EC2 instances
import boto3
ec2 = boto3.resource('ec2')
def lambda_handler(event, context):
# create filter for instances in running state
filters = [
{
'Name': 'instance-state-name',
'Values': ['running']

FWIW: I (@rondy) am not the creator of the content shared here, which is an excerpt from Edmond Lau's book. I simply copied and pasted it from another location and saved it as a personal note, before it gained popularity on news.ycombinator.com. Unfortunately, I cannot recall the exact origin of the original source, nor was I able to find the author's name, so I am can't provide the appropriate credits.


Effective Engineer - Notes

What's an Effective Engineer?

library(quantstrat)
library(magrittr)
Xt = getSymbols('2498.TW', auto.assign = F)
# 1st Step: Attach MA indicators onto symbol
Xt$MA5 = Xt %>% Cl %>% SMA(5)
Xt$MA60 = Xt %>% Cl %>% SMA(60)
@wojteklu
wojteklu / clean_code.md
Last active May 7, 2024 00:25
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules