Skip to content

Instantly share code, notes, and snippets.

@garcia556
garcia556 / get.c
Created December 3, 2017 21:08
POSIX shared memory IPC example (shm_open, mmap), working on Linux and macOS
#include <stdio.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#define STORAGE_ID "/SHM_TEST"
#define STORAGE_SIZE 32
int main(int argc, char *argv[])
@bithavoc
bithavoc / postgres-notify-trigger.sql
Last active August 15, 2024 15:15
I used this trigger to notify table changes via NOTIFY (migrating off RethinkDB)
CREATE OR REPLACE FUNCTION notify_trigger() RETURNS trigger AS $$
DECLARE
channel_name varchar DEFAULT (TG_TABLE_NAME || '_changes');
BEGIN
IF TG_OP = 'INSERT' THEN
PERFORM pg_notify(channel_name, '{"id": "' || NEW.id || '"}');
RETURN NEW;
END IF;
IF TG_OP = 'DELETE' THEN
PERFORM pg_notify(channel_name, '{"id": "' || OLD.id || '"}');
@ramybenaroya
ramybenaroya / Enum.js
Last active September 23, 2020 10:47 — forked from xmlking/Enum.es6.js
JavaScript Enums with ES6, Type Checking, Immutability and dynamic public methods
/*eslint-disable */
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*eslint-enable */
function getEnumClass(options = {}, _EnumSymbol){
function EnumClass() {
_classCallCheck(this, EnumClass);
@fritzy
fritzy / 1_triggers.sql
Last active April 7, 2024 20:07
Get table change notifications from Postgres as JSON
CREATE OR REPLACE FUNCTION table_update_notify() RETURNS trigger AS $$
DECLARE
id bigint;
BEGIN
IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE' THEN
id = NEW.id;
ELSE
id = OLD.id;
END IF;
PERFORM pg_notify('table_update', json_build_object('table', TG_TABLE_NAME, 'id', id, 'type', TG_OP)::text);
@derekseymour
derekseymour / freshdesk_sso.js
Last active June 17, 2020 15:59
Freshdesk Single Sign On URL - Node.js
var crypto = require('crypto');
/**
* Generates and returns a Freshdesk Single Sign On URL
* {@link https://gist.github.com/derekseymour/26a6fe573c1274642976 Gist}
*
* @author Derek Seymour <derek@rocketideas.com>
* @param {String} name - The name of the user logging in.
* @param {String} email - A valid email address to associate with the user.
@Shrulik
Shrulik / STS_FederationToken_nodejs
Created March 18, 2014 16:43
This is a simple example of how to use STS.getFederationToken and its result to perform actions with the new credentials, in this case S3.putObject
var aws = require('aws-sdk')
aws.config.update({accessKeyId: nconf.get('AWS_KEY'),
secretAccessKey: nconf.get('AWS_SECRET')});
var STS = new aws.STS({apiVersion: '2011-06-15'});
var tempCred = STS.getFederationToken(
{'Name': token, 'Policy': JSON.stringify(policy), 'DurationSeconds': 90000},
function (err, data) {
@timhudson
timhudson / express.js
Last active January 17, 2019 11:34
Internal routing within a single node process using express
var request = require('request')
, express = require('express')
, app = express()
var port = process.env.PORT || 5000
app.get('/api', function(req, res) {
res.send('I am from the API')
})
@lijoantony
lijoantony / 1.cpp
Created November 17, 2012 17:50
Example program to demonstrate the usage of curl multi interface with boost::asio
boost::asio::io_service io_service;
boost::asio::deadline_timer timer(io_service);
@ashblue
ashblue / nodejs-recursive-directory.js
Created October 19, 2012 05:06
NodeJS recursive directory listing without a module package
/**
* Goes through the given directory to return all files and folders recursively
* @author Ash Blue ash@blueashes.com
* @example getFilesRecursive('./folder/sub-folder');
* @requires Must include the file system module native to NodeJS, ex. var fs = require('fs');
* @param {string} folder Folder location to search through
* @returns {object} Nested tree of the found files
*/
// var fs = require('fs');
function getFilesRecursive (folder) {
@sandfox
sandfox / CertificateGeneration.sh
Created February 15, 2012 00:11
TLS certificate inspection example (using nodejs)
###
#Step 1 - Generate server certificates etc... (most of this code is horribly ripped off from nodejs docs currently -> http://nodejs.org/docs/latest/api/tls.html)
###
#Assuming your starting from a clean directory
mkdir server
cd server
#generate private key