Skip to content

Instantly share code, notes, and snippets.

View kparkov's full-sized avatar

Kristian Videmark Parkov kparkov

View GitHub Profile
@kparkov
kparkov / upload.jade
Last active January 15, 2020 14:27
Multer uploads #javascript #node
doctype html
html
head
title File uploads
body
form(method="post", action="/file", enctype="multipart/form-data")
input(type="file", name="file")
input(type="submit", value="Upload")
@kparkov
kparkov / cron.sh
Last active September 25, 2017 18:59
Follow cron syslog
tail -f /var/log/syslog | grep CRON
@kparkov
kparkov / tslint.json
Last active September 3, 2018 18:44
tslint.json in typescript react
{
"extends": ["tslint:recommended", "tslint-react", "tslint-config-prettier"],
"linterOptions": {
"exclude": [
"config/**/*.js",
"node_modules/**/*.ts"
]
},
"rules": {
"variable-name": [true, "allow-leading-underscore"],
@kparkov
kparkov / subcommand.sh
Created August 27, 2018 14:15
Bash CLI interface with subcommands
command="${1: }"
arguments="${@:2}"
case ${command} in
-h)
help
;;
--help)
help
;;
@kparkov
kparkov / alias.sh
Created November 6, 2018 09:41
Show $PATH with line breaks between entries
alias pl="sed 's/:/\n/g' <<< \"$PATH\""
@kparkov
kparkov / .bash_profile
Created November 6, 2018 10:36
Simple PS1
# Directory $
export PS1="\n\W \\$ "
# With red dir and orange $
export PS1="\n\[\e[31m\]\W\[\e[m\] \\[\e[33m\]$\[\e[m\] "
@kparkov
kparkov / migrate.sh
Last active November 16, 2018 19:08
Copy a list of git repositories from one remote to another
#!/bin/bash
# This pulls a list of repositories from repositories.txt, and pushes each of them to their new location, including all
# branches and tags.
#
# Please note the following:
# - unless the remote is configured to allow a repository to be created when pushing,
# the destination repository should be created and empty.
# - repositories.txt should have a newline at end of file, otherwise it will not process the last
# entry.
@kparkov
kparkov / api.csproj
Created February 10, 2019 13:08
Swashbuckle .NET Core XML Documentation relative path
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>bin\$(Configuration)\Api.xml</DocumentationFile>
@kparkov
kparkov / TypeSafeEnumAlternative.cs
Last active September 27, 2020 16:38
Type safe Enum alternative
public class Role
{
public static Role Author {get;} = new Role(0, "Author");
public static Role Editor {get;} = new Role(1, "Editor");
public static Role Administrator {get;} = new Role(2, "Administrator");
public static Role SalesRep {get;} = new Role(3, "Sales Representative");
public string Name { get; private set; }
public int Value { get; private set; }
@kparkov
kparkov / Example.cs
Created February 27, 2019 23:18
Upload stream
[HttpPost, Route("project/{projectId}/folder/{folderId}/upload")]
public async Task<object> UploadFile(string projectId, string folderId)
{
var request = Request;
// This solution was provided by: http://www.asp.net/web-api/overview/advanced/sending-html-form-data-part-2
// Check if the request contains multipart/form-data.
if (!Request.Content.IsMimeMultipartContent())
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);