Skip to content

Instantly share code, notes, and snippets.

🛰
Refactoring the mothership

Eugen Tudorancea ugin

🛰
Refactoring the mothership
Block or report user

Report or block ugin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ugin
ugin / index.js
Created Jun 4, 2019
Native history undo / redo for ProseMirror
View index.js
// source:
// https://github.com/dmonad/prosemirror-native-undo-redo-example/blob/master/index.js
import { EditorState } from 'prosemirror-state'
import { EditorView } from 'prosemirror-view'
import { Schema, DOMParser } from 'prosemirror-model'
import { schema } from 'prosemirror-schema-basic'
import { addListNodes } from 'prosemirror-schema-list'
import { exampleSetup } from 'prosemirror-example-setup'
import { undo, redo } from 'prosemirror-history'
@ugin
ugin / nginx.conf
Last active Feb 1, 2019
Craft CMS nginx configuration
View nginx.conf
map $scheme $hsts_header {
https max-age=31536000;
}
map $sent_http_location $craft_http_location {
default $sent_http_location;
~https://__DOMAIN_NAME_DEV__/(?<suffix>.*) "https://__DOMAIN_NAME__/$suffix";
}
error_log __ABSOLUTE_PATH_TO_PROJECT__/logs/error.log debug;
@ugin
ugin / nginx_install.sh
Last active Feb 7, 2019
Install nginx from source with string replacement support in HTTP headers and body
View nginx_install.sh
#!/usr/bin/env bash
set -e
# names of latest versions of each package
export NGINX_VERSION=1.15.8
export VERSION_ZLIB=zlib-1.2.11
export VERSION_PCRE=pcre-8.42
export VERSION_LIBRESSL=libressl-2.9.0
export VERSION_NGINX=nginx-$NGINX_VERSION
@ugin
ugin / readme.md
Last active Mar 6, 2018
Use secondary SSH keys for GitHub / GitLab
View readme.md

Create secondary SSH key and add it to agent:

ssh-keygen -t rsa -b 4096 -C "user@server.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa_user

Create a SSH config file and add the new key:

@ugin
ugin / index.js
Created Jan 15, 2017
Calculating Color Contrast
View index.js
// via http://24ways.org/2010/calculating-color-contrast/
function bestContrastYIQ(colors) {
var r = colors[0]
var g = colors[1]
var b = colors[2]
var yiq = (r * 299 + g * 587 + b * 114) / 1000;
return (yiq >= 128) ? 'black' : 'white';
}
@ugin
ugin / segment.js
Created Aug 5, 2016
Parse URL path segment for routing
View segment.js
/*
Splits a route segment into tokens
'users' -> literal = 'users'
'{id}' -> key = 'id'
'{ticket?}' -> key = 'ticket', optional = '?'
'{admin*}' -> key = 'admin', wildcard = '*'
result = '{id}'.match(TOKENS)
@ugin
ugin / mkdir.js
Last active Aug 1, 2016
Node.js `mkdir -p` version (ES6)
View mkdir.js
import { dirname } from 'path'
import fs from 'fs'
const mkdir = (path, done) => {
// if multiple paths need to be created
// will be called recursively
function mkdir (path, callback) {
fs.mkdir(path, (error) => {
if (!error) {
@ugin
ugin / nginx.conf
Last active May 7, 2018
nginx configuration for local development
View nginx.conf
worker_processes auto;
worker_rlimit_nofile 4096;
events {
worker_connections 4096;
multi_accept on;
}
http {
# settings for sending static files
@ugin
ugin / extract.sh
Last active Jan 1, 2016
bash helper functions
View extract.sh
#!/bin/bash
# Extracts archived files / mounts disk images
# Usage: extract <file>
extract () {
if [ -f $1 ]; then
case $1 in
*.tar.bz2) tar -jxvf $1 ;;
*.tar.gz) tar -zxvf $1 ;;
*.bz2) bunzip2 $1 ;;
@ugin
ugin / git.md
Last active Aug 29, 2015
git - common problems and fixes
View git.md

Restore a deleted file:

# find the file
git rev-list -n 1 HEAD -- [file]
# checkout the file
git checkout [commit id]^ -- [file]

Revert a file to a previous commit:

You can’t perform that action at this time.