Skip to content

Instantly share code, notes, and snippets.

@pkrnjevic
pkrnjevic / traverse_node.go
Created January 29, 2021 23:17 — forked from xeoncross/traverse_node.go
Simple DOM node traversal in golang using a very useful collector/matcher function
package main
import (
"bytes"
"fmt"
"io"
"strings"
"unicode"
"golang.org/x/net/html"
package main
import (
"flag"
"log"
"net/http"
"strings"
)
// FileSystem custom file system handler
@pkrnjevic
pkrnjevic / stringify.json
Last active June 12, 2017 19:18
Gist showing how to JSON.stringify objects with circular references. Useful when dumping Express requests or dom.
// Note: cache should not be re-used by repeated calls to JSON.stringify.
var cache = [];
JSON.stringify(req, function(key, value) {
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) {
// Circular reference found, discard key
return;
}
// Store value in our collection
@pkrnjevic
pkrnjevic / catfile.go
Last active March 10, 2016 03:20
One way to concatenate a lot of files quickly (352k in 2m48sec) ... inspired by http://randyzwitch.com/gnu-parallel-medium-data/
// catfile.go
// one possible way to concatenate files quickly
// inspired by http://randyzwitch.com/gnu-parallel-medium-data/
// runtime on mb pro15 (late 2013): 352k files concatentaed in 2m48sec
//
package main
import (
. $topsrcdir/browser/config/mozconfig
export MOZ_APP_NAME=securebrowser
export MOZ_APP_DISPLAYNAME=SecureBrowser
mk_add_options MOZ_APP_NAME=securebrowser
mk_add_options MOZ_APP_DISPLAYNAME=SecureBrowser
ac_add_options --enable-application=browser
mk_add_options MOZ_OBJDIR=c:/mozilla-objs-msvc
@pkrnjevic
pkrnjevic / fsevents_windows.go
Last active March 24, 2024 10:15
Windows USN Journal sample in Go based on Jeffrey Richter's superb MSDN Journal article. A work in progress, intended to provide similar API to go.fsevents.
//
// File: fsevents_windows.go
// Date: October 29, 2013
// Author: Peter Krnjevic <pkrnjevic@gmail.com>, on the shoulders of many others
//
// This code sample is released into the Public Domain.
//
package fsevents
import (
@pkrnjevic
pkrnjevic / gist:6348746
Created August 27, 2013 01:35
Sample angular service using CoffeeScript class.
class ThumbService
constructor: (@$log, @$q, @$resource, @mainService) ->
console.log "ThumbService: constructor called"
@url = @mainService.url(true)+"rest/thumbs/:value/:count"
@thumbs_url = @$resource @url
@sf = []
@lines = []
@thumbs = []
@thumb_size = 150
@max_thumbs = 200
class MyFunc
constructor: ->
@name = "default name"
return "Hello from MyFunc(). this.name = " + @name
$get: ->
@name = "new name"
"Hello from MyFunc.$get(). this.name = " + @name
app = angular.module("app", [])
@pkrnjevic
pkrnjevic / inotify-example.cpp
Last active February 28, 2023 13:30
This simple inotify sample monitors changes to "./tmp". Recursive monitoring of file and directory create and delete events is implemented, but monitoring pre-existing "./tmp" subfolders is not. A C++ class containing a couple of maps is used to simplify monitoring. The Watch class is minimally integrated, so as to leave the main inotify code ea…
//
// File: inotify-example.cpp
// Date: July 16, 2013
// Author: Peter Krnjevic <pkrnjevic@gmail.com>, on the shoulders of many others
//
// This is a simple inotify sample program monitoring changes to "./tmp" directory (create ./tmp beforehand)
// Recursive monitoring of file and directory create and delete events is implemented, but
// monitoring pre-existing "./tmp" subfolders is not.
// A C++ class containing a couple of maps is used to simplify monitoring.
// The Watch class is minimally integrated, so as to leave the main inotify code
@pkrnjevic
pkrnjevic / gist:5125165
Created March 9, 2013 18:31
Snippet using libepeg (in Go).
C.epeg_decode_size_set(im.cim, C.int(width), C.int(height))
C.epeg_quality_set(im.cim, C.int(quality))
var scaledData *C.uchar
var scaledSize C.int
C.epeg_memory_output_set(im.cim, &scaledData, &scaledSize)
C.epeg_encode(im.cim)