Skip to content

Instantly share code, notes, and snippets.

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

Nick Porter surjikal

👁️‍🗨️
  • CTO @ 42
  • Oakland
View GitHub Profile
package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
)
@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
app.directive 'chartScatterplot', (Utils, Stats) ->
restrict: 'E'
scope:
model: '='
class: '@'
aggregate: '='
showOutliers: '='
@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 / mergesort.js
Created May 14, 2013 06:24
mergesort.js
;(function() {
var mergesort = (function() {
function merge(leftArray, rightArray) {
if ((leftArray || []).length < 1) return rightArray;
if ((rightArray || []).length < 1) return leftArray;
var leftIndex = 0
, rightIndex = 0
@surjikal
surjikal / README.md
Created April 20, 2013 01:45
CSS customer filter notes
@surjikal
surjikal / 1-shader-directive.coffee
Last active December 16, 2015 07:48
Angular Things!
###
An quick way to add custom shaders to blocks:
<shader shader-vertex="/path/to/shader.vert" shader-fragment="/path/to/shader.frag">...</shader>
###
app.directive 'shader', ->
restrict: 'EA'
replace: true
transclude: true
@surjikal
surjikal / fib-generator.js
Last active December 16, 2015 02:19
A fibonacci generator in JavaScript, because why not.
// Ex.
// fib = new FibonacciGenerator();
// for (var i = 0; i < 10; i++)
// console.log( fib.next() );
var FibonacciGenerator = function(prev, curr) {
var prev = parseInt(prev) || 0
, curr = parseInt(curr) || 1;
var next = function(oldPrev, oldCurr) {
@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 / tricks.coffee
Created March 26, 2013 23:58
CoffeeScript Tricks
# Enumerate, python-style
enumerate = (list) ->
index = 0
list.map (item) -> [index++, item]
for [index, item] in enumerate(['bacon','sauce'])
console.log index, item