Skip to content

Instantly share code, notes, and snippets.

@kennethkalmer
kennethkalmer / gist:278814
Created January 16, 2010 13:14
node.js SMTP Server
/*
smtpd.js is SMTP server written for node.js
MIT License
*/
var tcp = require('tcp');
var sys = require('sys');
@tombigel
tombigel / pre-commit
Created July 13, 2011 16:31
GIT pre-commit test for capital letters in image file names and for debug commands
#!/bin/sh
#
# A hook script to verify that no images with capital letters are committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# Go through all the changed files (except for deleted and unmerged)
#
# Check for lines containing "debugger" "console." or "alert("
@vi
vi / README
Created September 5, 2012 03:16
Create tun/tap device that just copies all packets to/from the given ethernet interface.
Primary use case: workaround non-working "ip link set wlan0 netns ..." for some network drivers.
Secondary use case: simple demo for getting/setting the MAC address, tun/tap, raw sockets...
Pre-built version: http://vi-server.org/pub/tap_copy
@austinhyde
austinhyde / js-observables-binding.md
Last active August 16, 2023 18:19
Vanilla JavaScript Data Binding

Observables

You don't really need a framework or fancy cutting-edge JavaScript features to do two-way data binding. Let's start basic - first and foremost, you need a way to tell when data changes. Traditionally, this is done via an Observer pattern, but a full-blown implementation of that is a little clunky for nice, lightweight JavaScript. So, if native getters/setters are out, the only mechanism we have are accessors:

var n = 5;
function getN() { return n; }
function setN(newN) { n = newN; }

console.log(getN()); // 5

setN(10);

@williamtu
williamtu / gist:438477daedc3823ac8882f9110fb2cc4
Last active September 6, 2023 13:35
create tun/tap device and read/write
cat tunclient.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <net/if.h>
#include <linux/if_tun.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
export const h=(t,p,...c)=>({t,p,c,k:p&&p.key})
export const render=(e,d,t=d.t||(d.t={}),p,r,c,m,y)=>
// arrays
e.map?e.map((e,p)=>render(e,d,t.o&&t.o[p])):
// components
e.t.call?(e.i=render((render.c=e).t(Object.assign({children:e.c},e.p),e.s=t.s||{},t=>
render(Object.assign(e.s,t)&&e,d,e)),t.i||d,t&&t.i||{}),d.t=t=e):(
// create notes
m=t.d||(e.t?document.createElement(e.t):new Text(e.p)),
// diff props
@paulkaplan
paulkaplan / colorTempToRGB.js
Last active March 4, 2024 10:29
Color Temperature to RGB
// From http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/
// Start with a temperature, in Kelvin, somewhere between 1000 and 40000. (Other values may work,
// but I can't make any promises about the quality of the algorithm's estimates above 40000 K.)
function colorTemperatureToRGB(kelvin){
var temp = kelvin / 100;
@rofl0r
rofl0r / init.c
Created August 6, 2013 21:15
minimal init daemon by rich felker, author of musl libc
#define _XOPEN_SOURCE 700
#include <signal.h>
#include <unistd.h>
int main()
{
sigset_t set;
int status;
if (getpid() != 1) return 1;
@laobubu
laobubu / ABOUT.md
Last active March 23, 2024 05:28
A very simple HTTP server in C, for Unix, using fork()

Pico HTTP Server in C

This is a very simple HTTP server for Unix, using fork(). It's very easy to use

How to use

  1. include header httpd.h
  2. write your route method, handling requests.
  3. call serve_forever("12913") to start serving on port 12913
@ajdavis
ajdavis / dnssd.cpp
Created July 28, 2017 18:59 — forked from scaryghost/dnssd.cpp
How to do a SRV or TXT record lookup in C/C++ on Linux.
/**
* compile: g++ -std=c++0x -o dnssd dnssd.cpp -lresolv
* Your g++ compiler must have lambda support
*
* Code based on examples from:
* http://www.cs.columbia.edu/~zwb/project/dotslash/dots_apache/dnsc.c
* http://people.samba.org/bzr/jerry/slag/unix/query-srv.c
*/
#include <arpa/nameser.h>
#include <functional>