Skip to content

Instantly share code, notes, and snippets.

View agoalofalife's full-sized avatar
😉
Do what you can, with what you have, where you are

Ilya Chubarov agoalofalife

😉
Do what you can, with what you have, where you are
View GitHub Profile
@agoalofalife
agoalofalife / function_overloading.js
Last active July 6, 2017 07:15
function overloading depend count arguments js
function addMethod(object, name, fn) {
var old = object[name]
object[name] = function(){
console.log(fn, 'fn')
if (fn.length == arguments.length) {
return fn.apply(this, arguments)
} else if (typeof old == 'function') {
return old.apply(this, arguments)
@agoalofalife
agoalofalife / GO_MYSQL_EXAMPLE.go
Last active July 6, 2017 07:15
Classic exanpl mysql Golang (SELECT)
import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
"log"
"os"
"fmt"
)
type User struct {
id int
// link playground https://play.golang.org/p/VGPJNwdvjH
func insertion_sort(arr []int) []int {
var (
twoPosition int
onePosition int
comparisonItem int
)
for onePosition = 1; onePosition < len(arr); onePosition++ {
comparisonItem = arr[onePosition]
<?php
trait Tree
{
protected $nameChildAttribute = 'children';
public function getTree(\Illuminate\Support\Collection &$tree, $nameMethod) : array
{
foreach ($tree as &$parent)
{
@agoalofalife
agoalofalife / statistic.go
Last active April 19, 2017 09:13
statistic.go
package main
import (
"fmt"
"log"
"net/http"
"sort"
"strconv"
"strings"
"math"
package main
import (
"log"
"fmt"
"os"
"path/filepath"
"strings"
)
/**
* Generates unique id (mix datetime and random).
* @param {number=} len Required length of id (16 by default).
* @returns {string} Generated id.
*/
function genUID(len){
function base36(val){
return Math.round(val).toString(36);
}
// для escape значений
function escapeHtml (string) {
return String(string).replace(/[&<>"'`=\/]/g, function fromEntityMap (s) {
return entityMap[s];
});
}
var entityMap = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
<?php
abstract class DomainObjectAbstract
{
protected $_id = null;
/**
* Get the ID of this object (unique to the
* object type)
*
* @return int
let name = 'Maria';
let name2 = 'Vasilij';
let age = 18;
let result = tag`My name ${name} sd sdc sdc and ${name2} and ${age}`;
function tag(srting,...values) {
return srting.reduce((prev,current,id) => {
if (id > 0) {
if (typeof values[id - 1] == 'string') {