Skip to content

Instantly share code, notes, and snippets.

View JohannesFischer's full-sized avatar

Johannes Fischer JohannesFischer

View GitHub Profile
@JohannesFischer
JohannesFischer / RegEx
Last active February 17, 2017 02:39
RegEx I think I will use again
# CSS
# add missing semicolon to last property
([^;])$(\n})
$1;$2
# Shorten hex color values
#([\da-f])\1([\da-f])\2([\da-f])\3\b
#$1$2$3
@JohannesFischer
JohannesFischer / settings.json
Last active September 10, 2018 07:04
My Visual Studio Code User Settings
// Place your settings in this file to overwrite the default settings
{
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.wordWrap": "off",
"editor.detectIndentation": false,
"files.associations": {
"*.css.erb": "css",
"*.ejs": "html",
"*.pac": "javascript",
@JohannesFischer
JohannesFischer / git-commands.sh
Last active October 12, 2022 10:08
List of useful git commands
# Delete remote branch
git push origin :branch-name
# Set upstream
git branch --set-upstream-to=upstream/branchname
# Shorthand for diff of git commit with its parent
git diff COMMIT^!
# or
git diff-tree -p COMMIT
@JohannesFischer
JohannesFischer / snippets.cson
Last active October 6, 2016 02:43
My Atom Snippets
# Your snippets
#
# Atom snippets allow you to enter a simple prefix in the editor and hit tab to
# expand the prefix into a larger code block with templated values.
#
# You can create a new snippet in this file by typing "snip" and then hitting
# tab.
#
# An example CoffeeScript snippet to expand log to console.log:
#
@JohannesFischer
JohannesFischer / npm.sh
Last active September 6, 2016 01:24
Useful npm commands
# Go to package repo page
npm repo $package
# Go to package home page
npm home $package
# List outdated packages
npm outdated
# Remove extraneous packages
# ~/.bashrc: executed by bash(1) for non-login shells.
# run after updating: source ~/.bashrc
# some lazy ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Alias definitions.
# You may want to put all your additions into a separate file like
@JohannesFischer
JohannesFischer / post-merge
Last active June 1, 2016 00:58
Git post merge hook: Run npm install when packackage.json changed
#/usr/bin/env bash
# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
}
@JohannesFischer
JohannesFischer / .gitignore
Created February 26, 2016 06:51
my default gitignore file
# Packages
*.xpi
*.zip
# Logs and databases
*.log
*.sql
*.sqlite
# OS generated files
@JohannesFischer
JohannesFischer / localstorage-poly.js
Last active February 19, 2016 08:24
localStorage polyfill (non persistent)
try {
window.localStorage.setItem('testKey', '1');
window.localStorage.removeItem('testKey');
}
catch (error) {
window.localStorage = {
_data: {},
setItem: function(id, val) { return this._data[id] = String(val); },
getItem: function(id) { return this._data.hasOwnProperty(id) ? this._data[id] : undefined; },
removeItem: function(id) { return delete this._data[id]; },
@JohannesFischer
JohannesFischer / average.php
Created February 18, 2016 10:33
Average color
<?php
$filename = 'IMAGE_PATH';
$image = imagecreatefromjpeg($filename);
$width = imagesx($image);
$height = imagesy($image);
$pixel = imagecreatetruecolor(1, 1);
imagecopyresampled($pixel, $image, 0, 0, 0, 0, 1, 1, $width, $height);
$rgb = imagecolorat($pixel, 0, 0);
$color = imagecolorsforindex($pixel, $rgb);
?>