This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| version: '2' | |
| services: | |
| zookeeper1: | |
| restart: always | |
| image: wurstmeister/zookeeper:latest | |
| container_name: zookeeper1 | |
| ports: | |
| - "2181:2181" | |
| kafka1: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class AuthHeadersInterceptor : Interceptor | |
| { | |
| public AuthHeadersInterceptor(IHttpContextAccessor httpContextAccessor) | |
| { | |
| _httpContextAccessor = httpContextAccessor; | |
| } | |
| public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(TRequest request, ClientInterceptorContext<TRequest, TResponse> context, AsyncUnaryCallContinuation<TRequest, TResponse> continuation) | |
| { | |
| var metadata = new Metadata |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| httpClientBuilder.ConfigureChannel(o => | |
| { | |
| // add SSL credentials | |
| o.Credentials = new SslCredentials(); | |
| // allow invalid/untrusted certificates | |
| var httpClientHandler = new HttpClientHandler | |
| { | |
| ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator | |
| }; | |
| var httpClient = new HttpClient(httpClientHandler); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| services.AddTransient<AuthHeadersInterceptor>(); | |
| services.AddHttpContextAccessor(); | |
| var httpClientBuilder = services.AddGrpcClient<MygRpcService.MygRpcServiceClient>(o => { o.Address = new Uri("grpc-endpoint-url"); }); | |
| httpClientBuilder.AddInterceptor<AuthHeadersInterceptor>(); | |
| httpClientBuilder.ConfigureChannel(o => o.Credentials = ChannelCredentials.Insecure); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class JwtTokenValidator : ISecurityTokenValidator | |
| { | |
| public bool CanReadToken(string securityToken) => true; | |
| public ClaimsPrincipal ValidateToken(string securityToken, TokenValidationParameters validationParameters, out SecurityToken validatedToken) | |
| { | |
| var handler = new JwtSecurityTokenHandler(); | |
| var tokenValidationParameters = new TokenValidationParameters | |
| { | |
| ValidateIssuer = true, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void ConfigureServices(...) { | |
| services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) | |
| .AddJwtBearer(o => { | |
| var validator = new JwtTokenValidator(...); | |
| o.SecurityTokenValidators.Add(validator); | |
| }); | |
| services.AddAuthorization(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void Configure(...) { | |
| app.UseRouting(); | |
| app.UseAuthentication(); | |
| app.UseAuthorization(); | |
| app.UseEndpoints(... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function memorySizeOf(obj) { | |
| var bytes = 0; | |
| function sizeOf(obj) { | |
| if(obj !== null && obj !== undefined) { | |
| switch(typeof obj) { | |
| case 'number': | |
| bytes += 8; | |
| break; | |
| case 'string': |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # See list of docker virtual machines on the local box | |
| $ docker-machine ls | |
| NAME ACTIVE URL STATE URL SWARM DOCKER ERRORS | |
| default * virtualbox Running tcp://192.168.99.100:2376 v1.9.1 | |
| # Note the host URL 192.168.99.100 - it will be used later! | |
| # Build an image from current folder under given image name | |
| $ docker build -t gleb/demo-app . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function detectBrowserByFeatures() { | |
| // Opera 8.0+ | |
| var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0; | |
| // Firefox 1.0+ | |
| var isFirefox = typeof InstallTrigger !== 'undefined'; | |
| // Safari 3.0+ "[object HTMLElementConstructor]" | |
| var isSafari = /constructor/i.test(window.HTMLElement) || (function(p) { | |
| return p.toString() === "[object SafariRemoteNotification]"; |