Skip to content

Instantly share code, notes, and snippets.

View jaz303's full-sized avatar

Jason Frame jaz303

  • Glasgow, Scotland, UK
  • 06:59 (UTC +01:00)
View GitHub Profile
@jaz303
jaz303 / gist:6212654
Created August 12, 2013 16:40
Actors
<!DOCTYPE html>
<html>
<head>
<title>Actor</title>
<script>
// things i wanted to try but never got round to:
//
// - option to make `actor` a single function that is called once per message
function Foo() {
this.destructors = [];
}
Foo.prototype.bind = function(ele, type, handler) {
ele.addEventListener(type, handler);
this.destructors.push(function() {
ele.removeEventListener(type, handler);
});
}
@jaz303
jaz303 / gist:6029803
Created July 18, 2013 14:31
private data patterns in JS
// I saw this programming style somewhere a while back and liked it.
function PubSub(subject) {
var observers = [];
subject.notify = function() {
for (var i = 0; i < observers.length; ++i) {
try {
observers[i].apply(null, arguments);
} catch (e) {
@jaz303
jaz303 / gist:6010349
Created July 16, 2013 16:37
Evaluate code in the context from which exception was thrown
# http://stackoverflow.com/questions/106920/how-can-i-get-source-and-variable-values-in-ruby-tracebacks
class StandardError
alias_method :initialize_old, :initialize
attr_reader :binding
def initialize(*args)
initialize_old *args

I'm trying to design a circuit that will allow a button to trigger only for a single clock pulse. This was my first attempt, using 2 D flip-flops (using Logisim for now):

Circuit

The button provides the rising edge which loads high into the first flipflop, and Q1 goes high, then second picks this up on the next clock pulse and Q2 will go high. Q2 going high triggers an async reset on the first flipflop, making Q2 go low on the next pulse.

First question - is this sensible? Perhaps there's a much easier way? (if so, ignore the next question :)

Second question - I had a go at designing a real circuit for this but there's a problem. On quad D flipflop ICs the async reset is shared between all flipflops on the chip, so my reset mechanism won't work here (the second flipflop would immediately be reset when Q2 goes high). So I came up with this hack:

// port of this function:
// https://github.com/openssl/openssl/blob/master/crypto/evp/evp_key.c#L115
var crypto = require('crypto');
var passphrase = new Buffer("secretsecretsecret", "utf8");
var iv = new Buffer("02E2EFAFD7D550A6", "hex");
var addmd = 0;
var md_buf = new Buffer(0);
def foo(x)
puts x
foo(x+1)
end
foo 1
#ifndef BUFFERPOOL_H
#define BUFFERPOOL_H
#include <QObject>
template <class T, class R = T>
class ObjectPool
{
public:
ObjectPool(int count)
function array_diff(foo, bar) {
var d=[], i=0, j=0;
foo.sort();
bar.sort();
while (i < foo.length && j < bar.length) {
var l = foo[i], r = bar[j];
if (l < r) {
d.push(l);
i++;
} else if (l == r) {
// trying to do this:
var fn = new Function("foo", "bar", "baz", "return foo + bar + baz;");
// with arbitrary number of args:
var args = ["foo", "bar", "baz"];
var src = "return foo + bar + baz;"
// with a non-ctor fn i'd do:
var allArgs = args.slice(0);
allArgs.push(src);