Skip to content

Instantly share code, notes, and snippets.

@belichuk
belichuk / test.php
Created June 24, 2014 21:55
patTemplate vs. Twig
<?php
function microtime_float()
{
list($usec, $sec) = explode(' ', microtime());
return ((float)$usec + (float)$sec);
}
require_once "../sqlconn.php";
$params = array(
'doctype' => '<!DOCTYPE html>',
{
"always_show_minimap_viewport": true,
"color_scheme": "Packages/User/Monokai (SL).tmTheme",
"draw_minimap_border": true,
"enable_telemetry": false,
"font_face": "Consolas",
"font_size": 14.0,
"theme": "Gravity.sublime-theme",
"trim_automatic_white_space": false,
"word_wrap": false,
@belichuk
belichuk / test.php
Created April 15, 2015 12:12
PHP performance: function vs closures vs
<?php
$iter = 1000000;
$start = microtime(true);
function func($item) { return $item; };
for ($i = 0; $i < $iter; $i++)
{
func($i);
}
$end = microtime(true) - $start;
@belichuk
belichuk / mimimi
Last active January 25, 2016 16:13
function c(b,a){return b+Math.round(Math.random()*(a-b))}
function d(){this.reset=function(){this.a.width=c(100,200);this.x=-this.a.width;this.y=c(0,window.innerHeight-100);this.a.style.zIndex=3E3;this.a.style.left=this.x+"px";this.a.style.top=this.y+"px";this.speed=c(1,5)};this.a=document.createElement("img");this.a.src="https://raw.githubusercontent.com/TakWolf/NyanCatEverywhere/master/img/nyancat.gif";this.a.style.position="fixed";this.b=!0;document.body.appendChild(this.a);this.reset();this.update=function(){this.b?0===c(0,180)&&(this.b=!1,this.reset()):
(this.x+=this.speed,this.a.style.left=this.x+"px",this.x>window.innerWidth+this.a.width&&(this.b=!0))};this.remove=function(){this.a.remove();this.update=function(){}}}for(var e=[],f=(new Date).getTime(),g=0;20>g;g++)e[g]=new d;var h=document.createElement("audio");h.autoplay="autoplay";h.loop="loop";var k=document.createElement("source");k.src="http://ringon.ru/uploads/mp3-090/serebro-mi_mi_mi-ringon.ru.mp3";k.type="audio/mpeg";h.appendChild(k);document.
if (!Function.prototype.bind) {
Function.prototype.bind = function(oThis) {
if (typeof this !== 'function') {
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
}
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function() {},
fBound = function() {
@belichuk
belichuk / index.js
Created May 16, 2018 16:22
Find all palindromes made from the product of two 4-digit numbers
const fs = require('fs');
const reverseNum = s => String(s).split('').reverse().join('');
const genPalindrome = (len) => {
const palindromes = new Set();
const mod = len%2 !== 0;
const iLen = ~~(len/2);
const start = Math.pow(10, iLen - 1);
const end = Math.pow(10, iLen) - 1;
for (let i = end; i >= start; i--)
@belichuk
belichuk / main.java
Created June 11, 2018 09:10
Find all palindromes made from the product of two 4-digit numbers ( Java )
package com.pal;
import java.io.File;
import java.io.FileOutputStream;
public class Main {
public static void main(String[] args) throws Exception {
File file = new File("output.txt");
file.createNewFile();
@belichuk
belichuk / index.js
Created February 18, 2019 16:42
Overlap
// input:
// 0 4 9 10
// <-----------|-------------------------|---------------->
// true false true
// [[0,4,true],[4,9,false],[9,10,true]]
// 0 6 10
// <-----------------------|------------------------------>
// true false
// [[0,6,true],[6,10,false]]
const shift = (offset, points) => points.map(pt => {
const point = typeof pt == 'object' ? pt : JSON.parse(pt);
return {x: point.x + offset.x, y: point.y + offset.y};
});
const polyline = [
{x: 0, y: 0},
{x: 10, y: 10},
'{"x": 20, "y": 20}',
{x: 30, y: 30},
@belichuk
belichuk / index.js
Last active April 26, 2023 17:51
reverse list javascript
class List {
constructor(head = null) {
this.head = head
}
insert(newNode) {
let node = this.head;
if (node==null) {
this.head = newNode;
return;