Skip to content

Instantly share code, notes, and snippets.

@kraih
kraih / detach.pl
Created September 18, 2013 00:46
use Mojolicious::Lite;
# Catch magical detach exception and rethrow everything else
hook around_dispatch => sub {
my ($next, $c) = @_;
return if eval { $next->(); 1 };
die $@ unless $@ eq "MOJO_DETACH\n";
};
# Throw magical detach exception
@branneman
branneman / better-nodejs-require-paths.md
Last active May 25, 2026 22:56
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

#!/usr/bin/env python2.7
# From HurlSly@reddit: http://www.reddit.com/r/Bitcoin/comments/1vxszh/selfish_mine_simulation_in_python/
import random
def Simulate(alpha,gamma,N):
#This function simulate the selfish miners strategy.
#It returns the proportion of blocks in the longest chain
#which belongs to the selfish miners.
state=0
@ciaranarcher
ciaranarcher / golang-cheat.md
Last active December 27, 2018 14:26
golang cheatsheet

Types

type Vertex struct {
    Lat, Long float64
}

Maps

@ernix
ernix / plenv-install-perl-5.8.9-i386.sh
Created April 28, 2014 07:46
Install 32bit perl on Mac OSX with plenv
plenv install 5.8.9 \
-Dcc=gcc \
-Dld=g++ \
-Dusethreads \
-Duseithreads \
-Duseshrplib \
-Accflags="-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk" \
-Accflags="-mmacosx-version-min=10.6" \
-Accflags="-arch i386 -DUSE_SITECUSTOMIZE -Duselargefiles" \
-Aldflags="-Wl,-search_paths_first -arch i386" \
@gavinandresen
gavinandresen / BlockPropagation.md
Last active May 21, 2025 19:15
O(1) block propagation

O(1) Block Propagation

The problem

Bitcoin miners want their newly-found blocks to propagate across the network as quickly as possible, because every millisecond of delay increases the chances that another block, found at about the same time, wins the "block race."

@seebz
seebz / iCal.php
Last active September 6, 2024 02:33
iCal PHP Parser
<?php
class iCal
{
/**
* @var string
*/
public $title;
@pixeline
pixeline / ajax-handler-wp.php
Last active October 5, 2022 13:09
Custom ajax handler for Wordpress. Using admin-ajax.php, as is usually recommended, is very slow and does not allow the use of plugin shortcodes. Using a custom ajax handler like this bypasses that. http://wordpress.stackexchange.com/questions/170808/the-content-shows-shortcode-instead-of-parsing-it
<?php
/*
WORDPRESS SPECIFIC AJAX HANDLER (because admin-ajax.php does not render plugin shortcodes).
by alexandre@pixeline.be
credits: Raz Ohad https://coderwall.com/p/of7y2q/faster-ajax-for-wordpress
*/
//mimic the actual admin-ajax
define('DOING_AJAX', true);
if (!isset( $_REQUEST['action']))
#!/usr/bin/perl
# Mojo::DOM を使い、
# DOM form オブジェクトのパラメータを取り出す例
use Mojo::DOM;
use Data::Dumper;
my $text = do { local $/ = undef; <DATA> };
my $dom = Mojo::DOM->new($text);
my $forms = forms($dom);
print Data::Dumper->Dump( [$forms] ), "\n";
use Mojolicious::Lite;
use Mojo::EventEmitter;
helper events => sub { state $events = Mojo::EventEmitter->new };
get '/' => 'chat';
websocket '/channel' => sub {
my $c = shift;