Skip to content

Instantly share code, notes, and snippets.

@ample-samples
ample-samples / dot-product.lua
Last active May 5, 2024 03:29
Get the dot product of any MxN matrices
-- Utility functions for matrix.dot
local function dotScalar1dVector(scalar, v1)
local outputVector = {}
for i = 1, #v1, 1 do
outputVector[i] = v1[i] * scalar
end
return matrix(outputVector)
end
local function dotScalar2dVector(scalar, v1)
@sancar
sancar / README.md
Last active April 22, 2024 16:15
An upgradable read write lock for go

And upgradable read write lock for go

UpgradableRWMutex is an enhanced version of the standard sync.RWMutex. It has the all methods sync.RWMutex with exact same semantics. It gives more methods to give upgradable-read feature.

The new semantics for upgradable-read are as follows:

  • Multiple goroutines can get read-lock together with a single upgradable-read-lock.
  • Only one goroutine can have a write-lock and no read-lock/upgradable-read-lock can be acquired in this state.
@kconner
kconner / macOS Internals.md
Last active May 6, 2024 22:20
macOS Internals

macOS Internals

Understand your Mac and iPhone more deeply by tracing the evolution of Mac OS X from prelease to Swift. John Siracusa delivers the details.

Starting Points

How to use this gist

You've got two main options:

@tgross
tgross / vmctl
Created July 27, 2021 19:27
Fircracker virtual machine control script
#!/usr/bin/env bash
set -euo pipefail
help() {
cat <<EOF
vmctl [COMMAND] [ARGS]
Launch firecracker VMs from configuration templates with networks
managed by CNI. VM configuration is stored in $VM_CONFIG_DIR
and network configuration is stored in $NET_CONFIG_DIR
@thibaultcha
thibaultcha / README.md
Last active September 9, 2020 18:07
Align Nginx variables declarations with Vim

The Nginx code style asks for a specific alignment of variables declarations that is strainuous to manually enforce:

size_t                    slen;
uint32_t                  hash;
ngx_int_t                 rc;
const u_char             *p;
ngx_shm_zone_t           *shm_zone;
ngx_slab_pool_t          *shpool;
ngx_rbtree_node_t        *node, *sentinel;
ngx_ssl_session_t *sess;
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <uv.h>
#define DEFAULT_PORT 7000
#define DEFAULT_BACKLOG 128
@everilae
everilae / sqlite_json.py
Last active April 4, 2020 02:24
Hacky JSON support for SQLAlchemy SQLite dialect, if https://www.sqlite.org/json1.html extension is available.
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.dialects import plugins
from sqlalchemy.dialects.mysql.json import JSONIndexType, JSONPathType
from sqlalchemy.engine import CreateEnginePlugin
from sqlalchemy.sql.elements import BinaryExpression
from sqlalchemy.sql import sqltypes
from sqlalchemy.sql.operators import \
json_getitem_op, \
json_path_getitem_op
@AtulKsol
AtulKsol / db_backup_commands.md
Last active April 25, 2024 14:36
Commands to backup & restore database
  1. pg_dump is a nifty utility designed to output a series of SQL statements that describes the schema and data of your database. You can control what goes into your backup by using additional flags.
    Backup: pg_dump -h localhost -p 5432 -U postgres -d mydb > backup.sql

    Restore: psql -h localhost -p 5432 -U postgres -d mydb < backup.sql

    -h is for host.
    -p is for port.
    -U is for username.
    -d is for database.

@teknogeek0
teknogeek0 / elb2s3failover.template
Created November 7, 2014 22:10
For Re:Invent 2014, Deployment Automation talk - ELB to S3 Website "Fail Whale" failover CloudFormation template
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Create a Route53 Fail Whale failover setup from ELB to S3. You need a preexisting ELB, S3 bucket configured as a Website endpoint, and Hosted Zone.",
"Parameters" : {
"ELBDnsName" : {
"Type" : "String",
"Description" : "Your ELB's DNS Name"
},