Skip to content

Instantly share code, notes, and snippets.

@virolea
virolea / index.js
Created October 23, 2019 09:40
Configure axios to automatically set the Rails CSRF token
import axios from 'axios'
const tokenEl = document.getElementsByName('csrf-token')[0]
if (tokenEl) {
const token = tokenEl.getAttribute('content')
axios.defaults.headers.common['X-CSRF-Token'] = token
}
axios.defaults.headers.common['Accept'] = 'application/json'
axios.defaults.headers.post['Content-Type'] = 'application/json'

This is a quick sketch of how I think terminology applies to the various kinds of mocking and test doubles that apply in Go.

In practice, the most effective way to mock things in Go is to use an interface, and then to substitute a specialized testing implementation in place of a real one. Wherever a substitute is used, I think this should be called a "double".

There is one specialization of a "double" and that is a "fake" implementation. Fakes can often have real world uses, e.g: "RamDiskDatabase", but are typically

package main
import (
"fmt"
"time"
"github.com/go-redis/redis"
"github.com/kristoff-it/redis-memolock/go/memolock"
)
func main () {
@rupurt
rupurt / host_and_connect.sh
Last active April 30, 2018 20:36
Host & Connect to tmux session
# Hoster
# Serveo
ssh -R 1500:localhost:22 serveo.net
# ngrok
ngrok tcp 22
# tmux
tmux -S /tmp/pair
chmod 777 /tmp/pair
@Deub27
Deub27 / UIStackView+removeAll.swift
Created November 25, 2017 14:00
Remove all arranged subviews from UIStackView at once
import UIKit
extension UIStackView {
func removeAllArrangedSubviews() {
let removedSubviews = arrangedSubviews.reduce([]) { (allSubviews, subview) -> [UIView] in
self.removeArrangedSubview(subview)
return allSubviews + [subview]
}
@mscoutermarsh
mscoutermarsh / .rubocop.yml
Created October 29, 2017 17:42
Example rubocop file
AllCops:
Exclude:
- db/**/*
- Gemfile
- vendor/**/*
- config/environments/*
- bin/**/*
Rails:
Enabled: true
@DennisWeidmann
DennisWeidmann / NSImageExtension.swift
Last active January 9, 2023 10:10
Convert NSImage to CVPixelBuffer
extension NSImage {
func pixelBuffer() -> CVPixelBuffer? {
let width = self.size.width
let height = self.size.height
let attrs = [kCVPixelBufferCGImageCompatibilityKey: kCFBooleanTrue,
kCVPixelBufferCGBitmapContextCompatibilityKey: kCFBooleanTrue] as CFDictionary
var pixelBuffer: CVPixelBuffer?
let status = CVPixelBufferCreate(kCFAllocatorDefault,
Int(width),
Int(height),
@benjamincharity
benjamincharity / clearCache.sh
Created March 3, 2017 16:44
Clear the cache for a CircleCI project.
curl -X DELETE https://circleci.com/api/v1/project/:username/:project/build-cache?circle-token=:token
@b-r-o
b-r-o / FrameExtractor.swift
Last active December 9, 2019 15:21
TL;DR?
import UIKit
import AVFoundation
protocol FrameExtractorDelegate: class {
func captured(image: UIImage)
}
class FrameExtractor: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate {
private let position = AVCaptureDevicePosition.front
# Go to home directory
cd ~
# You can change what anaconda version you want at
# https://repo.continuum.io/archive/
wget https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh
bash Anaconda3-5.0.1-Linux-x86_64.sh -b -p ~/anaconda
rm Anaconda3-5.0.1-Linux-x86_64.sh
echo 'export PATH="~/anaconda/bin:$PATH"' >> ~/.bashrc