Skip to content

Instantly share code, notes, and snippets.

View lukaleli's full-sized avatar

Łukasz Leliński lukaleli

View GitHub Profile
@lukaleli
lukaleli / maintain-input-cursor.directive.ts
Created April 8, 2019 11:53
Angular directive to maintain cursor position in the input field in custom form input element
import { Directive, Input, HostListener, OnChanges, SimpleChanges, Renderer2, ElementRef } from '@angular/core';
@Directive({
selector: 'input[value]:not([ngModel])',
})
export class MaintainInputCursorDirective implements OnChanges {
@Input() value: string;
renderedValue = '';
constructor(private renderer: Renderer2, private element: ElementRef) {}
@lukaleli
lukaleli / config.ex
Created February 21, 2018 17:26 — forked from bitwalker/config.ex
Useful config wrapper for Elixir
defmodule Config do
@moduledoc """
This module handles fetching values from the config with some additional niceties
"""
@doc """
Fetches a value from the config, or from the environment if {:system, "VAR"}
is provided.
An optional default value can be provided if desired.
@lukaleli
lukaleli / bash-cheatsheet.sh
Created August 12, 2017 23:33 — forked from LeCoupa/bash-cheatsheet.sh
Bash CheatSheet for UNIX Systems
#!/bin/bash
#####################################################
# Name: Bash CheatSheet for Mac OSX
#
# A little overlook of the Bash basics
#
# Usage:
#
# Author: J. Le Coupanec
# Date: 2014/11/04
@lukaleli
lukaleli / MyComponent.js
Last active May 4, 2017 21:07
React + Redux: Simple function that maps specific props changes to specified component callbacks
// USAGE
import React, { Component } from 'react'
import { connect } from 'react-redux'
import mapPropsChangeToCallbacks from './mapPropsChangeToCallbacks'
// Specify props transition that should trigger specific callback
const mappings = [
{ method: 'onUploadStart', rule: (prev, next) => !prev.isUploading && next.isUploading },
{ method: 'onUploadEnd', rule: (prev, next) => prev.isUploading && !next.isUploading },
@lukaleli
lukaleli / wp.gitignore
Last active August 29, 2015 14:03
wordpress gitignore
###############################################################################
## #
## GIT IGNORE FOR WORDPRESS SITES #
## ------------------------------ #
## By: BigWilliam <hello@bigwilliam.com> #
## License: MIT - aka you can use/modify this how you want :) #
## #
###############################################################################
###############################################################################
# Eclipse
.project
.classpath
.settings
.checkstyle
# IntelliJ IDEA
.idea
*.iml
*.ipr
@lukaleli
lukaleli / framebuster.js
Created April 4, 2014 05:41
Framebuster - prevent your site from embedding in iframe
if (top.location != self.location) {
top.location = self.location.href;
}
@lukaleli
lukaleli / prevent mobile default behaviour
Last active December 24, 2015 09:29
prevent default touch events on mobile
-webkit-touch-callout:none;
-webkit-user-select:none;
-khtml-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
user-select:none;
@lukaleli
lukaleli / rwd
Created June 16, 2013 15:19
RWD media queries
/* Smartphones (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* STYLES GO HERE */
}
/* Smartphones (landscape) ----------- */
@media only screen
and (min-width : 321px) {
@lukaleli
lukaleli / getAverageRGB
Last active December 18, 2015 02:48
get average color of img (based on canvas feature)
function getAverageRGB(imgEl) {
var blockSize = 5, // only visit every 5 pixels
defaultRGB = {r:0,g:0,b:0}, // for non-supporting envs
canvas = document.createElement('canvas'),
context = canvas.getContext && canvas.getContext('2d'),
data, width, height,
i = -4,
length,
rgb = {r:0,g:0,b:0},