Skip to content

Instantly share code, notes, and snippets.

View icereval's full-sized avatar
🐈

Michael Haselton icereval

🐈
View GitHub Profile
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
# Bash installation script for https://github.com/choffmeister/git-describe-semver utility
# for use in --workspace_status command. We can't carry a bazel run dependency on this tool
# since we need to use it in --workspace_status.
git_describe_semver_url_base="https://github.com/choffmeister/git-describe-semver/releases/download"
git_describe_semver_version=0.3.9
@icereval
icereval / base.py
Last active July 7, 2018 14:37
Django Guardian Groups w/ Django ORM's Model Save Events
from django.contrib.auth.models import Group
from django.db import models
from django.db.models.signals import post_save, pre_save
from django.dispatch import receiver
from guardian.shortcuts import assign_perm
class EventModel(models.Model):
class Meta:
@dgilge
dgilge / 01_complete_authentication_as_api.md
Created June 15, 2018 11:15
How to implement all needed auth endpoints including login with OAuth2 for a SPA using Django REST framework, django-rest-auth and django-allauth

Complete authentication as API including OAuth2 endpoints

I implemented an auth API for a SPA. This is rarely documented and therefore I want to share here how I did it hoping it will be a help for others.

We are still working on it and I'll update this document accordingly.

This tutorial uses following versions:

Package Version
# Hack to extract module jar files into WEB-INF/classes (preferred).
Credit: https://stackoverflow.com/a/6676098
```xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
@mmellison
mmellison / grpc_asyncio.py
Last active April 3, 2024 15:48
gRPC Servicer with Asyncio (Python 3.6+)
import asyncio
from concurrent import futures
import functools
import inspect
import threading
from grpc import _server
def _loop_mgr(loop: asyncio.AbstractEventLoop):
@Faheetah
Faheetah / Jenkinsfile.groovy
Last active May 21, 2024 02:11
Jenkinsfile idiosynchrasies with escaping and quotes
node {
echo 'Results included as an inline comment exactly how they are returned as of Jenkins 2.121, with $BUILD_NUMBER = 1'
echo 'No quotes, pipeline command in single quotes'
sh 'echo $BUILD_NUMBER' // 1
echo 'Double quotes are silently dropped'
sh 'echo "$BUILD_NUMBER"' // 1
echo 'Even escaped with a single backslash they are dropped'
sh 'echo \"$BUILD_NUMBER\"' // 1
echo 'Using two backslashes, the quotes are preserved'
sh 'echo \\"$BUILD_NUMBER\\"' // "1"
from IPython.core.magic import Magics, magics_class, line_magic
import asyncio
@magics_class
class AsyncMagics(Magics):
@line_magic
def await(self, line):
return asyncio.get_event_loop().run_until_complete(eval(line, self.shell.user_global_ns, self.shell.user_ns))
@laserson
laserson / README.md
Last active July 25, 2016 01:41
Generate FlameGraph for Python code using plop

Create a FlameGraph to visualize where your code is spending its time.

Requires plop and FlameGraph.

@arvidfm
arvidfm / asyncio-tornado.py
Last active December 4, 2018 12:56
Running Tornado on asyncio's event loop, including 'yield from' support in request handlers
import asyncio
import tornado.concurrent
import tornado.ioloop
import tornado.web
import tornado.platform.asyncio
import tornado.httpclient
class ReqHandler(tornado.web.RequestHandler):
async def get(self):
function map (arr, func) {
return Promise.resolve().then(function () {
return arr.map(function (el) { return func(el) })
}).all()
}
function mapSeries (arr, func) {
let currentPromise = Promise.resolve()
let promises = arr.map(function (el) {
return currentPromise = currentPromise.then(function () {