Skip to content

Instantly share code, notes, and snippets.

View dmatveev's full-sized avatar
🌿

Dmitry Matveev dmatveev

🌿
View GitHub Profile
;; (in-package :aer-core)
(defclass backprop ()
())
(defgeneric process (neural-object input)
(:documentation "Process the input vector"))
(defgeneric calculate-deltas (layer context)
(:documentation "Calculate the deltas"))
PackageLoader fileInPackage: #PetitParser.
Object subclass: InfoParser [
InfoParser class >> fileParser [
<category: 'parsers'>
^self sectionParser trim star
=> [:nodes | Dictionary from: nodes]
]
InfoParser class >> sectionParser [
@dmatveev
dmatveev / buhurt.cc
Created May 15, 2011 21:13
Modifying object's state from a 'const' method without of const_cast<>(this) hacks
#include <iostream>
class Foo {
int bar;
int &baz;
public:
Foo() : bar(0), baz(bar) {
}
@dmatveev
dmatveev / gist:977243
Created May 17, 2011 19:51
A tiny and stupid function I use for section headers in my elisp code
(defun elisp-header (len text)
(interactive "p\nsHeader: ")
(let* ((total-len (if (< len 10) 80 len))
(text-len (length text))
(bar-len (/ (- total-len (+ 2 text-len)) 2))
(left-len (- total-len (+ (* 2 bar-len) 2 text-len)))
(inserter (lambda (len) (dotimes (i len) (insert ";")))))
(funcall inserter bar-len)
(insert (concat " " text " "))
(funcall inserter bar-len)
@dmatveev
dmatveev / gist:1025733
Created June 14, 2011 19:58
Filesystem activity producer
Object subclass: ActivityProducer [
| root allEntries actions |
ActivityProducer class >> root: aString [
<category: 'instance creation'>
^(self new)
init: aString;
yourself
]
@dmatveev
dmatveev / gist:1036558
Created June 20, 2011 20:53
Directory tree activity monitor
#include <glib.h>
#include <gio/gio.h>
#include <glib/gstdio.h>
#include <sys/resource.h>
static GHashTable *g_all_entries = NULL;
G_GNUC_INTERNAL G_LOCK_DEFINE (hash_lock);
static void
on_file_change (GFileMonitor *, GFile *, GFile *, GFileMonitorEvent, gpointer);
diff --git gio/kqueue/kqueue-thread.c gio/kqueue/kqueue-thread.c
index 6781c73..a08534d 100644
--- gio/kqueue/kqueue-thread.c
+++ gio/kqueue/kqueue-thread.c
@@ -24,6 +24,7 @@
#include <sys/event.h>
#include <sys/time.h>
#include <unistd.h>
+#include <errno.h>
#include <glib.h>
@dmatveev
dmatveev / gist:1198132
Created September 6, 2011 16:47
Invoking a protected method from a PIMPL
class Foo;
class Bar {
friend class Foo;
protected:
void aProtectedMethod() {
}
};
@dmatveev
dmatveev / gfiletest.c
Created September 11, 2011 11:53
GFileMonitor test for gio/kqueue GSoC project
#include <glib.h>
#include <glib/gprintf.h>
#include <gio/gio.h>
#include <string.h> /* memset, strlen */
#include <stdlib.h> /* system */
#define MAX_EXPECTED_EVENTS 10
#ifndef EVENT_EXPECT_TIME
# define EVENT_EXPECT_TIME 5
@dmatveev
dmatveev / gist:1267238
Created October 6, 2011 11:58
Simple logging code snippet
#include <windows.h>
#include <stdio.h>
#include <stdarg.h>
static CRITICAL_SECTION crit;
void log_init()
{
static volatile LONG done = 0;
if (done == 0) {