Skip to content

Instantly share code, notes, and snippets.

var LRUCache = require('mnemonist/lru-cache');
var getJobPostCache = new LRUCache(1000);
export const getJobPostJson = async (jobId: string) => {
const job = getJobPostCache.get(jobId)
if (job !== undefined) {
return ({
job,
isJobBelongsToThisUser: true
})
zplug "avivl/gcloud-project", use:init.sh
gmaps = googlemaps.Client(key=key)
reverse_geocode_result = gmaps.reverse_geocode(
(location['latitude'], location['longitude']))
now = datetime.datetime.now()
directions_result = gmaps.directions(
reverse_geocode_result[0]['formatted_address'],
home[0]['address'],
mode="driving",
departure_time=now)
fulfillment_text = Name + " will be home in %s" % \
@avivl
avivl / ifind.py
Last active September 8, 2018 12:24
api = PyiCloudService(user_mail, password)
location = api.iphone.location()
if location['isOld']:
fulfillment_text = "Can't get an accurate location for %s" % Name
body = '{"fulfillmentText":"%s"}' % fulfillment_text
return body
// Payload is the event's actual data inserted into data stores.
type Payload map[string]interface{}
// Type is an Event's metadata.
type Type struct {
EventVersionField string `json:"event_version" valid:"notempty,required"`
EventNameField string `json:"event_name" valid:"notempty,required"`
}
type Event struct {
func (c *Collector) Collect(ctx *fasthttp.RequestCtx) {
defer func(begin time.Time) {
responseTime := float64(time.Since(begin).Nanoseconds() / 1000)
occtx, _ := tag.New(context.Background(), tag.Insert(codeKey, strconv.Itoa(ctx.Response.StatusCode())), )
stats.Record(occtx, requestCounter.M(1))
stats.Record(occtx, requestlatency.M(responseTime))
}(time.Now())
/*do some stuff */
}
import (
"go.opencensus.io/stats"
"go.opencensus.io/tag"
"go.opencensus.io/stats/view"
)
var (
requestCounter *stats.Float64Measure
requestlatency *stats.Float64Measure
codeKey tag.Key
import (
"go.opencensus.io/exporter/prometheus"
"go.opencensus.io/exporter/stackdriver"
"go.opencensus.io/stats/view"
)
Exporter, err := prometheus.NewExporter(prometheus.Options{})
if err != nil {
logger.Error("Error creating prometheus exporter ", zap.Error(err))
}
def change_status(self, to_status, tagkey, tagvalue):
"""
Stop/start instance based on tags
Args:
to_status: 0 stop 1 start
tagkey: tag key
tagvalue: tag value
Returns:
def policy_checker(name):
"""
Check if there is a need to take an action for a policy.
Args:
name: policy name
Returns:
"""
policy = PolicyModel.query(PolicyModel.Name == name).get()