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
function getXMLHttpRequest() {
var xhr = null;
if (window.XMLHttpRequest || window.ActiveXObject) {
if (window.ActiveXObject) {
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
@dannygarcia
dannygarcia / test.js
Created September 17, 2012 01:32
test js syntax highlight
// 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);
}
};
@aqualungdesign
aqualungdesign / gist:4612606
Created January 23, 2013 20:19
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
@dflynn15
dflynn15 / xampp.sh
Created June 16, 2014 21:00
Fun bash script to write to XAMPP vhost and add symbolic link.
#!/bin/bash
# Format of command: ./xampp.sh new.website.name.com projectDir path/to/project/Dir
# Number of expected arguments
EXPECTED_ARGS=3
function create_symbolic_link {
sudo ln -s $1 /Applications/XAMPP/xamppfiles/htdocs/$2
}
@koorchik
koorchik / whatever-operator-in-js-proposal.md
Last active December 7, 2017 19:22
Shorter syntax for arrow functions

Inspired by the Perl6 pointy block short syntax (https://docs.perl6.org/type/Whatever) I like functional programming in JS. And it will be great to have even shorter syntax for lambdas (than arrow functions).

The compiler should detect special syntax and convert it to arrow functions.

Motivation: With shorter syntax it is clearer what is the intent of the code. Moreover, we do not write variable names twice. It is like when you contruct on object obj = {name: name, email: email} you use shorter syntax obj = {name, email}. Here it similar appoach.

Here are some examples. For every example bothe notation are the same.

@fczbkk
fczbkk / ajax.js
Created March 25, 2013 07:06
Minimalist AJAX function for the most basic calls. Only supports GET method. Loads given url and sends result to the callback function. Callback attribute is optional, sometimes you just want to ping the server and you don't care about the response.
function ajax (url, callback) {
callback = callback || function () {};
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
callback(xhr.responseText);
}
};
xhr.open("GET", url, true);
xhr.send();
@andrewluetgers
andrewluetgers / App.js
Last active March 10, 2021 17:39
Image loading with react-konva
import React, { Component } from 'react';
import DevTools from 'mobx-react-devtools';
import Konva from 'konva';
import {Stage, Layer, Rect, Line, Image} from 'react-konva';
import Img from './Img/Img.js';
import './App.css';
import pg from '../assets/scribo-doc-dia-00008061.json'
console.log(pg);
@A
A / sh_stats.sh
Last active March 13, 2021 02:29
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
}
@chicoxyzzy
chicoxyzzy / noncoercible.js
Last active March 15, 2021 17:09
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;
};
@A-gambit
A-gambit / ReactiveConf2017.md
Last active June 19, 2021 16:57
Proposal for lightning talk at ReactiveConf 2017: How do you make friends with React and FRP? 🤔 Start to develop your application using Focal.

How do you make friends with React and FRP? 🤔 Start to develop your application using Focal.

This is a CFP for the ⚡️Lightning⚡️ talk at awesome ReactiveConf 2017. If you'd like to see this talk, please 🌟 star🌟 this summary and retweet my tweet 🙂 #ReactiveConf

image

Functional reactive programming (FRP) is very popular nowadays. The JavaScript community provides us with excellent tools like RxJS, Bacon, and Kefir. But, as we know, they have nothing to do with React. So how we can use the power of FRP in our React application? Using the correct state management, we can make friends with FRP and React and make our application truly reactive. In my lightning talk, I will talk about Focal