Skip to content

Instantly share code, notes, and snippets.

@dotandimet
dotandimet / event-fun.js
Created March 2, 2021 15:16
An Observable object that emits change events
const EventEmitter = require('events');
class Observable extends EventEmitter {
constructor(source) {
super();
this.self = {};
from unittest.mock import Mock, patch
import mypackage
import other
def test():
thing = mypackage.get_my_class()
thing.method = Mock()
with patch('other.get_my_class',

Keybase proof

I hereby claim:

  • I am dotandimet on github.
  • I am dotandimet (https://keybase.io/dotandimet) on keybase.
  • I have a public key ASBvXbQcpCZJxHo87NkK0JKL76iohNUcYprHfDz_k-tt4Qo

To claim this, I am signing this object:

@dotandimet
dotandimet / 0_reuse_code.js
Created June 23, 2014 16:54
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@dotandimet
dotandimet / gist:7417509
Created November 11, 2013 18:05
Bug that drove me nuts, a reference to an array in the callback prevents process_feeds from emptying it...
# can you spot the bug below?
sub load_and_go {
my $self = shift;
$self->render_later();
my $subs = $self->backend->feeds->find({xmlUrl => $self->param('src')})->all;
$self->process_feeds(
$subs,
sub {
$self->redirect_to(
@dotandimet
dotandimet / gist:6595595
Created September 17, 2013 15:05
Tie::LevelDB and binary files
use File::Slurp;
use Tie::LevelDB;
my $file_name = shift; # give the script an image file argument - preferably a PNG.
my $db = new Tie::LevelDB::DB("db/");
my $buffer;
read_file( $file_name, binmode => ':raw', buf_ref => \$buffer );
@dotandimet
dotandimet / gist:5496319
Created May 1, 2013 16:21
jQuery hack to switch fargo outline item direction if it contains hebrew text.
$('.concord-text')
.each(function(t){
if ($(this).text().match(/[אבגדהוזחטיכלמנסעפצקרשת]/)) {
$(this).attr('dir', 'rtl');
};
});
@dotandimet
dotandimet / json_vs_mojo_json_true_false.t
Created October 25, 2012 15:20
tests to compare how JSON and Mojo::JSON generate true and false values in JSON
#!/usr/bin/env perl
use JSON;
use Mojo::JSON;
use Test::More tests => 6;
my $j = JSON->new;
my $mj = Mojo::JSON->new;
@dotandimet
dotandimet / gist:1164933
Created August 23, 2011 11:55
Trying to understand DBIx::Class::CDBICompat
package Unity::DBI;
use base qw/DBIx::Class::CDBICompat/;
package Unity::Cluster;
use base 'Unity::DBI';
__PACKAGE__->table('u_clusters');
__PACKAGE__->table_alias('u_clusters');
__PACKAGE__->sequence('obj_id');
__PACKAGE__->columns(Primary => qw/id/);
@dotandimet
dotandimet / capture.fcgi
Created August 21, 2011 07:29
Trying to use FCGI and output capture together
#!/usr/bin/perl
use warnings;
use strict;
use CGI::Fast;
use Capture::Tiny qw(capture);
use IPC::Run3 qw(run3);
my $cmd = 'date';