Skip to content

Instantly share code, notes, and snippets.

View audunolsen's full-sized avatar
🌷
Made a new avatar with Midjourney lmao

Audun Meek Olsen audunolsen

🌷
Made a new avatar with Midjourney lmao
View GitHub Profile
@audunolsen
audunolsen / .profile
Last active December 31, 2017 17:02
Shell script to open Xcode projects from the command line, call with $ xcode
####################
# Xcode #
####################
# Function to open Xcode projects from the command line, call with $ xcode (BASH version)
# Bash friendly version
function xcode {
proj=$( ls -d *.xcodeproj/ 2>/dev/null )
@audunolsen
audunolsen / .profile
Last active December 31, 2017 16:56
Shell script to compile and run c++ files with Make from the command line, call with $ cpp filename
####################
# C++ #
####################
# Function to compile and run c++ files from the command line, call with $ cpp filename
# Compiling and running c++ files with
# $ make filename && ./filename is overly verbose
# This function lessens on the typing required
@audunolsen
audunolsen / .zshrc
Created September 27, 2017 18:13
Show cwd, command and git dirty state all in the terminal's window/tab title.
# ~/.zshrc
# Override auto-title when static titles are desired ($ title My new title)
title() { export TITLE_OVERRIDDEN=1; echo -en "\e]0;$*\a"}
# Turn off static titles ($ autotitle)
autotitle() { export TITLE_OVERRIDDEN=0 }; autotitle
# Condition checking if title is overridden
overridden() { [[ $TITLE_OVERRIDDEN == 1 ]]; }
# Echo asterisk if git state is dirty
gitDirty() { [[ $(git status 2> /dev/null | grep -o '\w\+' | tail -n1) != ("clean"|"") ]] && echo "*" }
@audunolsen
audunolsen / styles.less
Last active November 10, 2017 08:11
A .less snippet to zero pad the gutter numbers in Atom
/* Zero pad the gutter numbers in Atom for a cleaner look. */
// loop through 1 - 9
@iterations: 8;
.double-zero-pad (@i) when (@i >= 0) {
.line-number[data-buffer-row="@{i}"]::before,
.git-line-removed[data-buffer-row="@{i}"]::before { content: '00' !important }
.double-zero-pad(@i - 1);
} .double-zero-pad (@iterations);
@audunolsen
audunolsen / roman-numerals-converter.coffee
Last active January 21, 2018 21:16
Short script written in CoffeeScript which converts a string containing roman numerals to an integer
### Convert string of roman numerals to an integer ###
convertSingleChar = (romanNumeral) ->
switch romanNumeral
when "I" then 1
when "V" then 5
when "X" then 10
when "L" then 50
when "C" then 100
@audunolsen
audunolsen / init.coffee
Last active January 15, 2018 14:05
A script for Atom which toggles the visibility of the wrap-guide if the preferred line length is exceeded. Will turn into a package at some point if Atom ever gets around to updating their API.
### ---------- CLEAN WRAP GUIDE ----------
The ergonomic factors of code readiablity include a preferred line length limit.
Automatic soft wrap is a nightmare because it hinders the "write first, refactor later"
mentality because it wrecks readability, an unusually long line is just a minor annoyance.
A wrap guide is a visual cue showing you if cleanup is necessary at a later point.
The problem: having a wrap guide visible at all times is distracting visual noise.
This script toggles the visibility of the wrap guide if a line exceeds the preferred line length.
@audunolsen
audunolsen / fibonacci.js
Last active January 22, 2018 12:01
A Javascript function returning an array with the desired length of the Fibonacci sequence
const fibonacci = length => {
const fibSeq = [1, 1];
if(length < 2) return fibSeq.splice(length, length);
for(let i = 2; i < length; i++) fibSeq.push(fibSeq[i-2] + fibSeq[i-1]);
return fibSeq;
}
console.log(fibonacci(50));
@audunolsen
audunolsen / fizzbuzz.js
Last active August 10, 2018 21:16
My blind attempt at a compact script for the FizzBuzz game.
for(i=1;i<101;i++)
o =i%3?'':'Fizz',
o+=i%5?'':'Buzz',
console.log(o||i)
@audunolsen
audunolsen / ObjFromArr.coffee
Created March 17, 2018 00:34
Handy oneliner for converting an array to an object.
ObjFromArr = (arr) => Object.assign {}, ...arr.map (item) => item
@audunolsen
audunolsen / 1-setCSSprops.js
Last active October 17, 2018 11:38
A method I defined on the CSSStyleDeclaration API prototype object for setting multiple properties at once
CSSStyleDeclaration.prototype.setProps = function(props) {
for (const prop in props) this.setProperty(prop, props[prop]);
}
/*
CONTEXT:
I'm usually not a proponent of setting styles through js, but I've recently
discovered that you can modify CSS variables with JS, which is YUUGE.