Skip to content

Instantly share code, notes, and snippets.

View mindscratch's full-sized avatar

Craig Wickesser mindscratch

View GitHub Profile
@mindscratch
mindscratch / server.go
Created January 20, 2014 18:24
TLS enabled HTTP Server in Go
package main
import (
"crypto/tls"
"fmt"
"log"
"net"
"net/http"
)
@mindscratch
mindscratch / secure_rails
Created February 25, 2013 10:07
Start WEBrick with SSL enabled. ## Usage bundle exec ruby script/secure_rails s -e <environment> -p <port>
#!/usr/bin/env jruby
%W{rails/command/server rack webrick webrick/https}.each { |lib| require lib }
ENV['HTTPS'] = 'on'
module Rails
class Server < ::Rack::Server
def default_options
super.merge({
@mindscratch
mindscratch / notes.md
Last active December 17, 2021 18:01
functional programming notes
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.Closeable;
import java.io.IOException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@mindscratch
mindscratch / notes.md
Created April 27, 2017 18:04
Debugging PHP Running in a Docker Container with XDebug and PHPStorm on macOS Sierra

I used docker compose to stand up MariaDB and Apache web server in containers.

xdebug

I'm using php7 with CentOS 7.2. I had to install "php70w-pecl-xdebug.x86_64". I also added the following the Dockerfile

RUN echo "xdebug.idekey = PHPSTORM" >> /etc/php.d/xdebug.ini &&
echo "xdebug.default_enable = 0" >> /etc/php.d/xdebug.ini &&
echo "xdebug.remote_enable = 1" >> /etc/php.d/xdebug.ini &&
echo "xdebug.remote_autostart = 0" >> /etc/php.d/xdebug.ini && \

@mindscratch
mindscratch / test.go
Created July 20, 2015 11:36
test code that uses julienschmidt/httprouter
import "github.com/julienschmidt/httprouter"
import "net/http"
func doRequest(method, uri string, body *bytes.Buffer, handle httprouter.Handle) (*httptest.ResponseRecorder, error) {
resp := httptest.NewRecorder()
req, err := http.NewRequest(method, uri, body)
if err != nil {
return nil, err
}
@mindscratch
mindscratch / cool.component.ts
Created January 8, 2021 15:28
NgRX parameterized selector problem
import { State } from '../shared';
constructor(store: Store<State>) {
// this call to errors because I haven't passed a "state"
store.select(selectNotificationsByGroupType(), { type: this.group.type });
}
@mindscratch
mindscratch / location.guard.spec.ts
Created December 31, 2020 17:35
Angular + Jest Mock Window Location
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';
import { WindowLocationToken } from '../location';
import { LocationHrefGuard } from './location-href.guard';
describe('LocationHrefGuard', () => {
let guard: LocationHrefGuard;
const routeMock: any = {
snapshot: {},
data: { pathname: '/app/logout.php' },
@mindscratch
mindscratch / rails_app_ssl_monkey_patch.rb
Created August 15, 2011 09:32
Rails (3.0.x): request.ssl? isn't working -- monkey patch
class Application < Rails::Application
# MONKEY PATCH
#
# Calls to request.ssl? aren't working. The ssl? method relies on some environment variable(s)
# to be set and doesn't take into account the 'rack.url_scheme'. See ticket #5750 on the Rails
# lighthouseapp.com ticketing site.
# url: https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5750-requestssl-should-reflect-rackurl_scheme
def call(env)
@mindscratch
mindscratch / capture_stdout.go
Created December 29, 2014 16:41
capture stdout in golang
import (
"bytes"
"io"
"os"
)
// not thread safe
func captureStdout(f func()) string {
old := os.Stdout
r, w, _ := os.Pipe()