Skip to content

Instantly share code, notes, and snippets.

@limitusus
limitusus / zero_division.md
Last active December 10, 2024 08:42
Zabbix: handle calculated item with zero division

Problem

Want to create a calculated item with last("X") / last("Y"). When Y = 0, the result should be 0.

Answer

last("X") * (1 - count("Y",#1,0)) / (last("Y") + count("Y",#1,0))
@chrj
chrj / template.service
Created May 4, 2018 14:09
Sample service unit file for systemd
[Unit]
Description=My service
[Service]
ExecStart=/usr/local/bin/my-service \
-argument value \
-otherargument othervalue
# Setuid/Setgid
User=nobody
@abstractart
abstractart / books.md
Last active May 26, 2025 16:54
Free Programming Ebooks - O'Reilly Media. Codeship free ebooks here - https://bit.ly/2oQ0knQ
@nathan-osman
nathan-osman / win32.go
Last active September 11, 2025 02:32
Simple Windows GUI application written in Go
package main
import (
"log"
"syscall"
"unsafe"
)
var (
kernel32 = syscall.NewLazyDLL("kernel32.dll")
angular.module('myApp').directive('myChart', function () {
var draw_line_chart = function(scope) { ... }
var draw_bar_chart = function(scope) { ... }
var setup_chart_interactions = function(scope) { ... }
// other helper functions ...
return {
templateUrl: '/views/my-chart.html',
restrict: 'E',
var cluster = require('cluster');
var PORT = +process.env.PORT || 1337;
if (cluster.isMaster) {
// In real life, you'd probably use more than just 2 workers,
// and perhaps not put the master and worker in the same file.
cluster.fork();
cluster.fork();
cluster.on('disconnect', function(worker) {
@domenic
domenic / interop.md
Last active July 7, 2022 19:47
`module.exports =` and ES6 Module Interop in Node.js

module.exports = and ES6 Module Interop in Node.js

The question: how can we use ES6 modules in Node.js, where modules-as-functions is very common? That is, given a future in which V8 supports ES6 modules:

  • How can authors of function-modules convert to ES6 export syntax, without breaking consumers that do require("function-module")()?
  • How can consumers of function-modules use ES6 import syntax, while not demanding that the module author rewrites his code to ES6 export?

@wycats showed me a solution. It involves hooking into the loader API to do some rewriting, and using a distinguished name for the single export.

This is me eating crow for lots of false statements I've made all over Twitter today. Here it goes.

@vedovelli
vedovelli / select2_directive.js
Created September 18, 2012 12:18
Select2 directive
rialabs.directive('riaSelect', function(){ /* This direct will be used as an HTML attribute: ria-select="{}" */
/* http://docs.angularjs.org/guide/directive */
return {
restrict: 'A', /* Limitates the use as an HTML attrbute */
require: 'ngModel', /* Requires the model to be used in this directive */
compile: function(tElement, tAttrs){ /* In the compile function, the <select> element is transformed by the plugin. */
var el = jQuery(tElement); /* tElement is a plain <select> */
el.select2(); /* Uses the plugin select2() */