Skip to content

Instantly share code, notes, and snippets.

View denysdovhan's full-sized avatar
👨‍💻
Working for @wix

Denys Dovhan denysdovhan

👨‍💻
Working for @wix
View GitHub Profile
// Simple ajax function to avoid using jQuery (°-°)
var ajax = function (url, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.send();
xhr.onreadystatechange = function (e) {
if (e.target.status === 200 && e.target.readyState === 4) {
callback(e.target.response);
}
};

Sass/Less Comparison

In this document I am using Sass's SCSS syntax. You can choose to use the indented syntax in sass, if you prefer it, it has no functional differences from the SCSS syntax.

For Less, I'm using the JavaScript version because this is what they suggest on the website. The ruby version may be different.

Variables

#!/bin/bash
# Might as well ask for password up-front, right?
sudo -v
# Keep-alive: update existing sudo time stamp if set, otherwise do nothing.
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
# Example: do stuff over the next 30+ mins that requires sudo here or there.
function wait() {
# Download and install XAMPP (Ubuntu 12.10)
# Depends on python-gtk2:i386 and python-glade2:i386 for the Control Panel
# If all else fails, XAMPP has step by step instructions at: http://www.apachefriends.org/en/xampp-linux.html
sudo add-apt-repository ppa:upubuntu-com/xampp;
sudo apt-get update;
sudo apt-get install xampp;
# Append the following if you're on a 64-bit system (~250MB)
sudo apt-get install ia32-libs
@denysdovhan
denysdovhan / sh_stats.sh
Last active August 29, 2015 14:21 — forked from A/sh_stats.sh
sh_stats () {
fc -l 1 | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n20
}
@denysdovhan
denysdovhan / pr.md
Created March 13, 2016 12:33 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@denysdovhan
denysdovhan / gist:0080d1bdcf5a43d19265e3b7225618f1
Created September 13, 2016 20:58 — forked from aqualungdesign/gist:4612606
iterm / oh-my-zsh -> rm move to .trash
#add script to .oh-my-zsh/lib/functions.zsh
function rm () {
local path
for path in "$@"; do
# ignore any arguments
if [[ "$path" = -* ]]; then :
else
local dst=${path##*/}
# append the time if necessary

@kangax's ES6 quiz, explained

@kangax created a new interesting quiz, this time devoted to ES6 (aka ES2015). I found this quiz very interesting and quite hard (made myself 3 mistakes on first pass).

Here we go with the explanations:

Question 1:
(function(x, f = () => x) {
@denysdovhan
denysdovhan / noncoercible.js
Created February 18, 2017 18:32 — forked from chicoxyzzy/noncoercible.js
Non-coercible objects
function nonCoercible(val) {
if (val == null) {
throw TypeError('nonCoercible shouldn\'t be called with null or undefined');
}
const res = Object(val);
res[Symbol.toPrimitive] = () => {
throw TypeError('Trying to coerce non-coercible object');
}
return res;
};
# based on: https://community.home-assistant.io/t/tuya-radiator-valve-ts0601-calibration-from-external-sensor-via-zigbee2mqtt/337991
# alternative: https://community.home-assistant.io/t/sync-trv-with-external-tempature-sensor/298024
blueprint:
name: Calibrate TRV temperature
description: Temperature calibration for Zigbee valve TS0601, according to external temperature sensor
domain: automation
input:
valve:
name: Valve