Skip to content

Instantly share code, notes, and snippets.

View mythz's full-sized avatar

Demis Bellot mythz

View GitHub Profile

Thread Pools

Thread pools on the JVM should usually be divided into the following three categories:

  1. CPU-bound
  2. Blocking IO
  3. Non-blocking IO polling

Each of these categories has a different optimal configuration and usage pattern.

@eevee
eevee / spabs.md
Last active February 20, 2024 08:29
tabs to spaces
@int128
int128 / README.md
Last active January 21, 2024 14:52
Watching build mode on Create React App

Create React App does not provide watching build mode oficially (#1070).

This script provides watching build mode for an external tool such as Chrome Extensions or Firebase app.

How to Use

Create a React app.

Put the script into scripts/watch.js.

@zelid
zelid / gist:6965002
Last active August 3, 2023 17:23
Examples of BulkInsert for PostgreSQL, MySQL and MS SQL using ServiceStack OrmLite. Work in progress...
public static void BulkInsertNpgsql<T>(this IDbConnection dbConn, IEnumerable<T> list, IEnumerable<string> insertFields = null)
{
if (list == null) return;
if (list.Count() < 1) return;
var objWithAttributes = list.FirstOrDefault();
var modelDef = OrmLiteConfig.GetModelDefinition(objWithAttributes.GetType());
if (insertFields == null) insertFields = new List<string>();
@munificent
munificent / gist:6136198
Created August 1, 2013 23:15
For kicks, I scraped Github's language pages and sorted them by rank
#1 JavaScript
#2 Ruby
#3 Java
#4 Shell
#5 Python
#6 PHP
#7 C
#8 C++
#9 Perl
#10 CoffeeScript
using System;
namespace RsaKeyConverter.Converter
{
public static class BytesExtensions
{
public static string ToBase64(this byte[] bytes)
{
return Convert.ToBase64String(bytes);
}
@coryt
coryt / ThrottlePlugin.cs
Created January 26, 2015 00:24
ServiceStack plugin to throttle api requests
public class ThrottlePlugin : IPlugin
{
/// <param name="redisHost">host name</param>
/// <param name="redisPort">port</param>
/// <param name="redisPassword">password</param>
public ThrottlePlugin(string redisHost, int redisPort, string redisPassword = null)
{
_redisClient = new RedisClient(redisHost, redisPort, redisPassword);
}
static Task<TResponse> Execute<TRequest, TResponse>(this Channel channel, TRequest request, string serviceName, string methodName,
CallOptions options = default, string? host = null)
where TRequest : class
where TResponse : class
=> Execute<TRequest, TResponse>(new DefaultCallInvoker(channel), request, serviceName, methodName, options, host);
static async Task<TResponse> Execute<TRequest, TResponse>(this CallInvoker invoker, TRequest request, string serviceName, string methodName,
CallOptions options = default, string? host = null)
where TRequest : class
where TResponse : class
{
@bamboo
bamboo / ReactiveServiceStack.cs
Last active May 11, 2019 16:00
Using ServiceStack* together with Reactive Extensions** to reduce the latency before the client can start processing the elements of an array response. The service sends elements to the client as soon as they become available through the magic of AsyncServiceBase, IStreamWriter, IObservable<T>.ToEnumerable() and careful use of WriteLine() and Fl…
using System;
using System.Collections.Generic;
using System.Disposables;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using Funq;
using ServiceStack.Common.Web;
using ServiceStack.Service;
@charlessolar
charlessolar / gist:4826cd1af0fabfac5b8f
Last active March 14, 2018 17:51
Servicestack OAuth JWT Verification
this.GlobalRequestFilters.Add((httpReq, httpResp, requestDto) =>
{
var header = httpReq.Headers["Authorization"];
if( header.IsNullOrEmpty() ) {
httpResp.StatusCode = (int)HttpStatusCode.Unauthorized;
httpResp.EndRequest();
}
try