Skip to content

Instantly share code, notes, and snippets.

@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;
Marquis de Lafayette's Early Life
Marquis de Lafayette was born in France in 1757. In 1759, his father passed away and in 1770, his mother and grandfather died.
In April 1771, at the age of fourteen, Lafayette entered the Royal Army. His parents were Marie Louise de La Rive and Michel du Motier. Marquis de Lafayette had no known siblings, as he was the only child of his parents. Defying the explicit orders of King Louis XVI, who did not wish to provoke Great Britain, Marquis de Lafayette left for America and crossed the Atlantic Ocean to assist the American rebels in 1777. Although he was still a teenager, spoke little English and lacked any battle experience, Lafayette convinced the Continental Army to commission him as a Major General on July 31, 1777.
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
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]]
@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 / 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;
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 / 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.
{
"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,