Skip to content

Instantly share code, notes, and snippets.

@droot
droot / gist:57ca90f7eec986d44b115b8abd35dc61
Created May 16, 2019 04:50
controller-tools-stack-overflow
go/bin/controller-gen "crd:trivialVersions=true" rbac:roleName=manager-role webhook paths="./api/...;./controllers/..." output:crd:artifacts:config=config/crd/bases
runtime: goroutine stack exceeds 1000000000-byte limit
fatal error: stack overflow
runtime stack:
runtime.throw(0x1784a61, 0xe)
/usr/local/go/src/runtime/panic.go:617 +0x72
runtime.newstack()
/usr/local/go/src/runtime/stack.go:1041 +0x6f0
runtime.morestack()
@droot
droot / k8s.go
Created September 26, 2018 19:21
K8s CLI example using controller-runtime
package main
import (
"context"
"fmt"
"os"
"k8s.io/api/core/v1"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"sigs.k8s.io/controller-runtime/pkg/client"
package main
import (
"fmt"
"os"
"path/filepath"
"regexp"
"strings"
"time"
@droot
droot / email_rest_handler.py
Created June 23, 2013 00:38
Gist presents quick code a REST handler for /emails service: POST /emails will be a webhook to consume request from an email service when a new email is received GET /emails -- returns email contents Get /emails/idxxxxx -- returns the info about an email content reference by id idxxxxxx
import json
from google.appengine.ext import db
from datetime import datetime
from base import BaseHandler
import logging
from models.emails import EmailContent
log = logging.getLogger(__name__)
@droot
droot / image.py
Last active December 17, 2015 00:10
This gist implements an Image Uploader Service in python using Google App Engine. There are four components. image.py implements the Image Model to persist Image Resource. image_service.py implements image service client which provides basis functionality of retrieving, saving, updating and deleting an image resource. image_rest_handler.py imple…
import datetime
from google.appengine.ext import db
class Image(db.Model):
"""Model to represent Image
"""
name = db.StringProperty(required = True)
data = db.TextProperty(required = True)
created_at = db.DateTimeProperty(auto_now_add = True)
updated_at = db.DateTimeProperty(auto_now = False)
@droot
droot / use_async_if.js
Created February 26, 2012 17:01
Use of Async IF construct
/* function to detect if a box of given color is visible on screen or not */
is_box_visible = function(color) {
var selector;
selector = "." + color + "box:visible";
return $(selector).length > 0;
};
$.when(async_if(is_box_visible, 'green') /* green box is visible */,
async_if(is_box_visible, 'red') /* red box is visible */
).then(
@droot
droot / async_if.js
Created February 26, 2012 16:47
Async IF Construct using JQuery Deferred
/* asynchronous IF construct implementation */
async_if = function(fn, args, timeout) {
var curr_probe, dfd, probe;
dfd = new jQuery.Deferred();
curr_probe = null;
probe = function() {
if (fn(args)) {
dfd.resolve(args); /* this will invoke success callback */
@droot
droot / async_if.coffee
Created February 26, 2012 16:31
Async IF Construct using JQuery Deferred
async_if = (fn, args, timeout)->
dfd = new jQuery.Deferred()
curr_probe = null
probe = ()->
if fn(args)
dfd.resolve(args)
curr_probe = null
else
curr_probe = setTimeout probe, 5
@droot
droot / redislogger_user.py
Created July 30, 2011 18:19
Redis Log Handler Use
log = logging.getLogger('')
rh = RedisLogHandler() #you can specify all redis params here
rh.setLevel(logging.WARNING) #set the filter for critical logs only
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') #custom formatter
rh.setFormatter(formatter)
log.addHandler(rh)
@droot
droot / redislogger.py
Created July 30, 2011 17:59
Redis Log Handler in Python
import redis
import logging
class RedisLogHandler:
"""Log handler for logging logs in some redis list
"""
def __init__(self, host = None, port = None, db = 0, log_key = 'log_key'):
self._formatter = logging.Formatter()
self._redis = redis.Redis(host = host or 'localhost', port = port or 6379, db = db)
self._redis_list_key = log_key