Skip to content

Instantly share code, notes, and snippets.

View olafkotur's full-sized avatar
💃
Aaaahhhh

Olaf Kotur olafkotur

💃
Aaaahhhh
View GitHub Profile
@olafkotur
olafkotur / toggle.applescript
Last active January 27, 2020 01:10
Toggles a given application on MacOS to either turn on or off depending on current state, can be used with a single keyboard short cut
on run
set appName to "YOUR APP NAME"
if application appName is running then
tell application appName to quit
end if
if application appName is not running then
tell application appName to activate
end if
@olafkotur
olafkotur / tmux.config
Created January 29, 2020 14:24
Configuration file for my Tmux preferences
# remap prefix from 'C-b' to 'C-a'
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
# Enable mouse control (clickable windows, panes, resizable panes)
set -g mouse on
# split panes using | and -
bind | split-window -h
@olafkotur
olafkotur / hacks.txt
Last active October 2, 2020 14:09
Simple command line snippets to set up some macOS preferences
# Allow the iOS simulator to be entered in full screen
defaults write com.apple.iphonesimulator AllowFullscreenMode -bool YES
# Increase the auto hide timer for it to never show
defaults write com.apple.dock autohide-delay -float 10; killall Dock
# Change the length of the dock animation
defaults write com.apple.dock autohide-time-modifier -float 0.25;killall Dock
@olafkotur
olafkotur / mongoService.ts
Created January 29, 2020 20:23
Service for running simple MongoDB functions
const MongoClient = require('mongodb').MongoClient;
const url = process.env.MONGODB_URI || 'mongodb://localhost:27017/';
let database: any = null;
export const MongoService = {
connect: () => new Promise((resolve: any) => {
MongoClient.connect(url, { useUnifiedTopology: true }, async (error: Error, db: any) => {
if (error) {
@olafkotur
olafkotur / emailService.ts
Created January 29, 2020 20:25
Email service for sending out emails via nodemailer
import nodemailer from 'nodemailer';
export const EmailService = {
send: async (subject: string, to: string, body: string) => {
const transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
secure: false,
auth: {
@olafkotur
olafkotur / .zshrc
Created January 29, 2020 20:28
Configuration for zshrc
# Preferences
export ZSH="/Users/olafkotur/.oh-my-zsh"
# Plugins
ZSH_THEME="olafkotur"
plugins=(git tmux)
source $ZSH/oh-my-zsh.sh
# Alias: Directories
alias dev="cd && cd ~/Development"
@olafkotur
olafkotur / promises.ts
Created January 29, 2020 20:29
Promises in Typescript
const data: ILiveData[] = await <any>MongoService.findOne('live', {});
findOne: async (collection: string, query: any) => {
return new Promise((resolve: any) => {
database.collection(collection).findOne(query, (error: Error, res: any) => {
if (error) {
throw error;
}
resolve(res);
});
@olafkotur
olafkotur / arrays.go
Created January 29, 2020 20:31
Array manipulation in Golang
// Removing: If you already know the index
someArray = append(someArray[:i], someArray[i+1:]...)
// Optional to remove multiple based on value
for i, value := range someArray {
if value == someOtherValue {
someArray = append(someArray[:i], someArray[i+1:]...)
}
}
@olafkotur
olafkotur / structs.go
Created January 29, 2020 20:31
Structs in Golang
// JSON
type SomeData struct {
Id int `json:"id"`
Status string `json:"status"`
}
var data []SomeData
data = append(data, SomeData{1, "Hello World"})
@olafkotur
olafkotur / mux.go
Created January 29, 2020 20:33
REST Server setup using Gorilla mux in Golang
import "github.com/gorilla/mux"
// Setup and create handlers
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/api/example", getExample).Methods("GET")
// Able to set up a function to execute before each request
_ = http.ListenAndServe(":"+port, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Do something here
router.ServeHTTP(w, r)