Skip to content

Instantly share code, notes, and snippets.

@johnjansen
johnjansen / httpsproxy.go
Created May 1, 2020 02:58 — forked from wwek/httpsproxy.go
https proxy in golang
// https://medium.com/@mlowicki/http-s-proxy-in-golang-in-less-than-100-lines-of-code-6a51c2f2c38c
// #!/usr/bin/env bash
// case `uname -s` in
// Linux*) sslConfig=/etc/ssl/openssl.cnf;;
// Darwin*) sslConfig=/System/Library/OpenSSL/openssl.cnf;;
// esac
// openssl req \
// -newkey rsa:2048 \
// -x509 \
require "crystagiri"
SEEN = Set(String).new
def parse(url)
return if SEEN.includes?(url)
SEEN.add url
begin
Crystagiri::HTML.from_url(url).css("a") do |anchor|
@johnjansen
johnjansen / tokenfield.coffee
Last active March 1, 2017 21:11
Coffeescript Tokenfield (with jQuery, step by step)
class window.Tokenfield
# create the object
constructor: (target)->
@properties=
target_object: $(target)
separator_key_codes: [9, 10, 12, 13] # maps to keyboard KEYS
separator_char_codes: [9, 10, 11, 12, 13, 44, 58, 59].map (i)-> String.fromCharCode(i) # characters (for paste)
del: [8]
min_input_width: 200 # default, can be overidden in css
token_list: []
@johnjansen
johnjansen / union_type.cr
Created October 12, 2016 22:49
Hack to - Define a variable as a union type from the outset in crystal-lang
some_var = [Int32.new(0), nil, ""].first
@johnjansen
johnjansen / cyrl.cr
Created October 1, 2016 15:53
The fastest way to download a file in Crystal ... ?
require "http/client"
module Cyrl
url = ARGV[0]
out_path = ARGV[1]
File.open(out_path, "w") do |output|
HTTP::Client.get(url) do |response|
IO.copy(response.body_io, output)
end
@johnjansen
johnjansen / Stackfile.yml
Last active July 22, 2016 07:07
ensure that only one of the current docker-cloud services can run at the same time (RUBY)
some_service:
image: some_image/that_runs_the_code_above:when_necessary
target_num_containers: 1 # dont use autoscaling ... kinda defeats the purpose
autorestart: false # you might think of a reason to make this autorestart ...
roles: # allow access to the api
- global
@johnjansen
johnjansen / reduce.scala
Last active December 4, 2015 05:54
Reduce, using iterator guards — Scala
// create a Range
val y = 1 to 20 // => Range(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)
// Reduce the list (ok its not a List, but you get the idea), just because!
val threes = for (i <- y if i % 3 == 0) yield i // => Vector(3, 6, 9, 12, 15, 18)
// and Map
val squares = for (i <- y if i % 3 == 0) yield i * i // => Vector(9, 36, 81, 144, 225, 324)
@johnjansen
johnjansen / main.scala
Last active December 4, 2015 05:06
AWS Lambda, Publish an SNS Message — Scala
package blahblah;
import scala.collection.JavaConverters._
import java.net.URLDecoder
import com.amazonaws.services.lambda.runtime.Context
import com.amazonaws.services.sns.AmazonSNSClient
import com.amazonaws.services.sns.model.PublishRequest
import java.io.{InputStream, OutputStream, PrintStream}
@johnjansen
johnjansen / build.sbt
Last active November 24, 2017 16:43
AWS Lambda Microservice — Scala
javacOptions ++= Seq("-source", "1.8", "-target", "1.8", "-Xlint")
lazy val root = (project in file(".")).
settings(
name := "lambda-demo",
version := "1.0",
scalaVersion := "2.11.4",
retrieveManaged := true,
libraryDependencies += "com.amazonaws" % "aws-lambda-java-core" % "1.0.0",
libraryDependencies += "com.amazonaws" % "aws-lambda-java-events" % "1.0.0",
@johnjansen
johnjansen / docker-golang.md
Last active August 21, 2016 10:29
Try Golang, without Golang

Experiment with golang without polluting your local

  1. install docker ... really, you need to look at containers !!!

  2. docker pull golang

  3. pretend we have go installed

        echo 'alias go="docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp golang go "' >> ~/.bash_profile
        source ~/.bash_profile