Skip to content

Instantly share code, notes, and snippets.

Avatar
⚔️
~

Ilia Andrienko andrienko

⚔️
~
View GitHub Profile
View uri components in and out
var e = encodeURIComponent;
var d = decodeURIComponent;
var paramsToURI = function(params){
var uri_components = [];
for(var i in params){
if(params.hasOwnProperty(i)) {
uri_components.push(e(i) + '=' + e(params[i]));
}
}
@andrienko
andrienko / extend.js
Created Mar 30, 2016
Yet another jquery-like deep extend implementation
View extend.js
module.exports = (function () {
var extend_single = function (destination, source, deep) {
for (var key in source) {
if (source.hasOwnProperty(key)) {
if (deep && typeof destination[key] == 'object' && typeof source[key] == 'object') {
destination[key] = extend_single(destination[key], source[key], deep);
} else {
destination[key] = source[key];
@andrienko
andrienko / percentage.php
Created Oct 10, 2016
PHP 5.2. Calculating percentage using largest remainder method (bit tricky)
View percentage.php
<?php
function calculate_percentage($aw,$tp=0,$t=0){
foreach($aw as $a) $t += $a['votes'];
foreach($aw as &$a)$tp += floor($a['percentage'] = $a['votes'] / $t * 100);
uasort($aw, 'sort_by_remainder');
foreach ($aw as &$v) $v['percentage'] = ($tp++ < 100) ? ceil($v['percentage']) : floor($v['percentage']);
ksort($aw);
return $aw;
}
@andrienko
andrienko / webpack.config.js
Created Nov 7, 2018
This is my webpack config. There are many webpack configs, and this one is mine!
View webpack.config.js
/* eslint-disable */
var path = require('path');
var MiniCssExtractPlugin = require('mini-css-extract-plugin');
var WriteFilePlugin = require('write-file-webpack-plugin');
var cssnano = require('cssnano');
var autoprefixer = require('autoprefixer');
var cssLoaderUse = function(asModules) {
return [
@andrienko
andrienko / index.fakeloading.js
Last active Nov 9, 2018
Minimal mobx store app with observables
View index.fakeloading.js
import React from "react";
import ReactDOM from "react-dom";
import { observable } from "mobx";
import { observer } from "mobx-react";
// Store
class Store {
@observable isLoading = false;
@andrienko
andrienko / monacoDragAndDropProvider.ts
Last active Jul 30, 2021
Monaco drag and drop provider
View monacoDragAndDropProvider.ts
import React from 'react';
import { editor } from 'monaco-editor';
import IMouseTarget = editor.IMouseTarget;
import IStandaloneCodeEditor = editor.IStandaloneCodeEditor;
import IContentWidget = editor.IContentWidget;
const { ContentWidgetPositionPreference } = editor;
export type TDropHandler = (e: React.DragEvent, target: IMouseTarget, instance: IStandaloneCodeEditor) => void;
export type TInstanceGetter = () => IStandaloneCodeEditor;