Skip to content

Instantly share code, notes, and snippets.

@powerman
powerman / gist:5456484
Last active December 16, 2015 15:29
Support for non-blocking Mojolicious app in CGI mode
use AnyEvent;
sub allow_non_blocking_cgi {
my ($module) = @_;
eval "require $module;" or die $@; ## no critic (ProhibitStringyEval)
my $startup = \&{$module.'::startup'};
my $wrapper = sub {
my ($app) = @_;
&{$startup};
my $done = AnyEvent->condvar;

Keybase proof

I hereby claim:

  • I am powerman on github.
  • I am powerman (https://keybase.io/powerman) on keybase.
  • I have a public key ASCSBOCcVZFOBR0em9fFkAAWPJX7QbEQq69BY9wDKS_n2Qo

To claim this, I am signing this object:

@powerman
powerman / tail.go
Created November 22, 2018 16:46
Template for tail.go
// Package tail implements behaviour of `tail -n 0 -F path`.
package tail
import (
"time"
)
var (
pollDelay = 200 * time.Millisecond // delay between polling to save CPU
pollTimeout = time.Second // how long to wait before returning os.ErrNotExist
package expdelay
import "time"
// ExpDelay implements exponential delay.
type ExpDelay struct{ cur, max time.Duration }
// New returns new exponential delay which start with min delay, increase
// each next delay in 2 times up to max delay.
//
func BenchmarkJSON(b *testing.B) {
for i := 0; i < b.N; i++ {
obj := Object{}
if err := json.Unmarshal(testCase, &obj); err != nil {
b.Fatal(err)
}
}
}
func BenchmarkFastJSON(b *testing.B) {
@powerman
powerman / graphviz_v1.md
Last active October 2, 2020 13:36
Gist+Graphviz example

Alt text

#CUT
digraph G {
    aize ="4,4";
    main [shape=box];
    main -> parse [weight=8];
    parse -> execute;
    main -> init [style=dotted];
 main -&gt; cleanup;
@powerman
powerman / gist:5468849
Created April 26, 2013 17:24
Using AnyEvent::DBI::MySQL with Mojolicious.
use AnyEvent::DBI::MySQL;
sub startup {
my $app = shift;
$app->config(db => {dsn=>…, login=>…, pass=>…});
$app->helper(dbh => sub { shift->{dbh} });
$app->helper(new_dbh => sub {
state $db = shift->app->config('db') or return;
@powerman
powerman / chan_queue.go
Created June 20, 2021 16:35
Helper for buffering data from non-blocking channel for sending into blocking channel
// Usage example:
func process(in <-chan Msg, outBlocking chan<- Msg) {
out := newQueueMsg(QueueSize, outBlocking)
for {
select {
case msg := <-in:
out.append(msg)
case out.C <- out.Elem:
out.del()
}
@powerman
powerman / OAuth 2.0.adoc
Created June 25, 2022 18:34
Recommendations on secure implementation of OAuth 2.0 (server and client)

OAuth 2.0

Table of Contents

Abstract

/*** MY OVERRIDES ***/
user_pref("_user.js.parrot", "overrides section syntax error");
/* [UX,-HIST] Restore previous session after Firefox restart. */
user_pref("browser.startup.page", 3); // 0102
/* [UX,-GEO] Allow websites to detect my locale. */
user_pref("intl.accept_languages", "ru,en-us,en"); // 0210
user_pref("javascript.use_us_english_locale", false); // 0211