Skip to content

Instantly share code, notes, and snippets.

View surjikal's full-sized avatar
👁️‍🗨️

Nick Porter surjikal

👁️‍🗨️
  • CTO @ 42
  • Oakland
View GitHub Profile
@surjikal
surjikal / macos-openssh-portable.sh
Last active February 1, 2024 23:21
Compile OpenSSH Portable on OSX / MacOS
#!/usr/bin/env bash
brew install openssl
git clone git://anongit.mindrot.org/openssh.git
cd openssh
# The './configure' script does not exist, so we have to build it
autoreconf
@surjikal
surjikal / encrypt-pw-ssha.sh
Last active May 26, 2023 18:45
Encrypt a password using SSHA. Use this for your `htpasswd` files.
#!/bin/sh
# http://wiki.nginx.org/Faq#How_do_I_generate_an_htpasswd_file_without_having_Apache_tools_installed.3F
PASSWORD=$1;
SALT="$(openssl rand -base64 3)"
SHA1=$(printf "$PASSWORD$SALT" | openssl dgst -binary -sha1 | sed 's#$#'"$SALT"'#' | base64);
printf "{SSHA}$SHA1\n"
@surjikal
surjikal / OAuth.cls
Created November 19, 2013 03:18
Apex 2-legged OAuth 1.0
public class OAuth {
public static HttpRequest signRequest(HttpRequest req, String consumerKey, String consumerSecret) {
String nonce = String.valueOf(Crypto.getRandomLong());
String timestamp = String.valueOf(DateTime.now().getTime() / 1000);
Map<String,String> parameters = new Map<String,String>();
parameters.put('oauth_signature_method','HMAC-SHA1');
parameters.put('oauth_consumer_key', consumerKey);
parameters.put('oauth_timestamp', timestamp);
@surjikal
surjikal / jquery.getstyleobject.js
Created June 27, 2012 21:57
jQuery - Get styles of an element
// Taken from http://upshots.org/javascript/jquery-copy-style-copycss
(function($) {
$.fn.getStyleObject = function() {
var dom = this.get(0);
var style;
var returns = {};
@surjikal
surjikal / conditional-basic-auth.conf
Created July 13, 2013 02:34
Nginx - Only apply basic auth if htaccess file exists
server {
listen 80;
server_name ~^(?<instance>.+?)\.foo.example.com$;
set $instance_root /instances/$instance.foo.example.com;
set $htaccess_user_file /htaccess/$instance.foo.example.com.htaccess;
root $instance_root;
# Abusing unused error codes to perform an internal redirect
@surjikal
surjikal / nginx-s3.conf
Last active April 9, 2022 03:32
Nginx - Wildcard subdomains, basic auth and proxying to s3. Set a policy to only allow your server's IP.
server {
listen 80;
server_name *.foo.example.com;
# We need this to resolve the host, because it's a wildcard.
# This is google's DNS server.
resolver 8.8.8.8;
include /etc/nginx/includes/proxy.conf;
@surjikal
surjikal / aws-xray-on-eks-fargate.md
Last active December 2, 2021 17:25
AWS X-Ray on EKS Fargate

This helm chart can be used to deploy a standalone daemon for AWS X-Ray on EKS Fargate.

  • You'll need to create a service account called aws-xray.
  • This IAM role works well: arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess
  • You will have to update the value for eks.amazonaws.com/role-arn.

Once this is deployed, you can set the AWS_XRAY_DAEMON_ADDRESS to aws-xray:2000 in your other pods.

{
"type": "shell",
"label": "python: futurize current file (dry run, vscode diff)",
"group": "build",
"command": "pipenv",
"args": [
"run",
"env",
"TMPDIR=$(mktemp -d)",
"futurize",
@surjikal
surjikal / csv.js
Last active November 5, 2020 19:58 — forked from ghuntley/gist:5064790
Generating a downloadable CSV file in the browser.
// assumes variable data, which is a homogenous collection of objects
// get keys
var keys = _.keys(data[0]);
// convert to csv string
var csv = keys.join(",");
_(data).each(function(row) {
csv += "\n";
csv += _(keys).map(function(k) {

Keybase proof

I hereby claim:

  • I am surjikal on github.
  • I am nickporter (https://keybase.io/nickporter) on keybase.
  • I have a public key whose fingerprint is C11F F917 2A56 60DC B631 89E3 4A5D DA1B 4DC6 6C1B

To claim this, I am signing this object: