Skip to content

Instantly share code, notes, and snippets.

Avatar

Steve Chavez steve-chavez

View GitHub Profile
@steve-chavez
steve-chavez / Arcan.nix
Created Apr 29, 2021 — forked from egasimus/Arcan.nix
Building Arcan on NixOS, 2020 version
View Arcan.nix
({ lib, newScope, stdenv, pkgs }: let
# nicer aliases
derive = stdenv.mkDerivation;
concat = builtins.concatStringsSep " ";
# vendored libuvc: don't build, just make sources available
libuvc-src = derive {
name = "libuvc-src";
# using fetchgit instead fetchFromGitHub because
View diff_demo.sql
-- This script was generated by the Schema Diff utility in pgAdmin 4
-- For the circular dependencies, the order in which Schema Diff writes the objects is not very sophisticated
-- and may require manual changes to the script to ensure changes are applied in the correct order.
-- Please report an issue for any failure with the reproduction steps.
BEGIN;
-- Cast: money -> bigint
View schema_diff_output.json
{
"success": 1,
"errormsg": "",
"info": "",
"result": null,
"data": [
{
"id": 326,
"type": "cast",
"label": "Casts",
@steve-chavez
steve-chavez / map.sql
Last active Jun 19, 2020
Create a OSM map from a pg function with PostgREST
View map.sql
-- From
-- + http://duspviz.mit.edu/tutorials/intro-postgis.php
-- + http://duspviz.mit.edu/web-map-workshop/leaflet_nodejs_postgis/
CREATE TABLE coffee_shops
(
id serial NOT NULL,
name character varying(50),
address character varying(50),
city character varying(50),
state character varying(50),
View deploy.nix
# From: https://stevechavez.xyz/nixops-blog.html
let
region = "us-east-2";
accessKeyId = "dev";
in {
network.description = "stevechavez.xyz";
resources = {
ec2KeyPairs.xyzKeyPair = { inherit region accessKeyId; };
elasticIPs.xyzIP = { inherit region accessKeyId; };
@steve-chavez
steve-chavez / nginx-tuning.md
Created Apr 25, 2020 — forked from denji/nginx-tuning.md
NGINX tuning for best performance
View nginx-tuning.md

Moved to git repository: https://github.com/denji/nginx-tuning

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@steve-chavez
steve-chavez / foundation.nix
Created Jan 13, 2020 — forked from monacoremo/foundation.nix
(Ab-)using Nix for full stack development environments
View foundation.nix
let
pkgs =
let
pinnedPkgs =
builtins.fetchGit {
name = "nixos-unstable-2019-12-05";
url = https://github.com/nixos/nixpkgs/;
rev = "cc6cf0a96a627e678ffc996a8f9d1416200d6c81";
};
in
@steve-chavez
steve-chavez / example.nginx
Created Jan 13, 2020 — forked from gsanders5/example.nginx
Automatic nginx virtual subdomains with sub-folders or sub-directories
View example.nginx
# Automatic nginx virtual subdomains with sub-folders or sub-directories
#
# Since the original source where I found this code is now offline, I have decided to mirror it here.
# All credit goes to: http://web.archive.org/web/20150307193208/http://www.messaliberty.com/2010/10/automatic-nginx-virtual-subdomains-with-sub-folders-or-sub-directories
#
# Description: In my web root directory I wanted create a folder called photos, and another called
# music using a sftp program. Without manually going back to the config file or to the shell I like to
# be able to access them at photos.nginxdomain.com and music.nginxdomain.com. That is what this config does.
# Redirect visitors from http://nginxdomain.com/ to http://www.nginxdomain.com/
@steve-chavez
steve-chavez / example.nginx
Created Jan 13, 2020 — forked from gsanders5/example.nginx
Automatic nginx virtual subdomains with sub-folders or sub-directories
View example.nginx
# Automatic nginx virtual subdomains with sub-folders or sub-directories
#
# Since the original source where I found this code is now offline, I have decided to mirror it here.
# All credit goes to: http://web.archive.org/web/20150307193208/http://www.messaliberty.com/2010/10/automatic-nginx-virtual-subdomains-with-sub-folders-or-sub-directories
#
# Description: In my web root directory I wanted create a folder called photos, and another called
# music using a sftp program. Without manually going back to the config file or to the shell I like to
# be able to access them at photos.nginxdomain.com and music.nginxdomain.com. That is what this config does.
# Redirect visitors from http://nginxdomain.com/ to http://www.nginxdomain.com/
View totp.pg.sql
CREATE EXTENSION pgcrypto;
CREATE OR REPLACE FUNCTION totp(key BYTEA, clock_offset INT DEFAULT 0) RETURNS INT AS $$
DECLARE
c BYTEA := '\x000000000' || TO_HEX(FLOOR(EXTRACT(EPOCH FROM NOW()) / 30)::INT + clock_offset);
mac BYTEA := HMAC(c, key, 'sha1');
trunc_offset INT := GET_BYTE(mac, 19) % 16;
result INT := SUBSTRING(SET_BIT(SUBSTRING(mac FROM 1 + trunc_offset FOR 4), 7, 0)::TEXT, 2)::BIT(32)::INT % 1000000;
BEGIN
RETURN result;
END;