Skip to content

Instantly share code, notes, and snippets.

Вопросы

  • Что произойдёт, если установить массиву нулевую длину?
  • Какими командами git приходилось пользоваться кроме pull, push, commit
  • Как задать свойство объекту, которое нельзя удалить
  • Самое крутое, что делали (чем гордитесь)

React

таймер на классах: https://codesandbox.io/s/dark-pond-764ou?file=/src/Timer.jsx

const { PassThrough, Writable } = require('stream');
process.on('uncaughtException', err => console.error('uncaughtException:', err))
const pass = new PassThrough()
const writable = new Writable({
write (chunk, encoding, callback) {
console.log('data:', chunk.toString())
callback()
}
export const addEventListener = (target, event, handler) => {
if (target.addEventListener) {
target.addEventListener(event, handler)
} else {
let key = `on${event.toLowerCase()}`
if (target.attachEvent) {
target.attachEvent(key, handler)
} else {
target[key] = handler
}
apt-get install -y git
cd $HOME && git clone https://github.com/calaba/octave-3.8.2-enable-64-ubuntu-14.04.git
cd octave-3.8.2-enable-64-ubuntu-14.04 \
&& echo 'export octave64src=/opt/octave-3.8.2' >> compile-params.in \
&& ./all.sh
@lbeschastny
lbeschastny / tree.clj
Last active November 5, 2015 21:33
Simple binary tree, implementing IPersistentCollection and IPersistentSet interfaces
(defn- -find
[{:keys [left right root] :as tree} pred el acc]
(if tree
(if (== root el)
[tree acc]
(if (pred root el)
(recur left pred el (conj acc :left))
(recur right pred el (conj acc :right))))
[nil acc]))
(defn merge-step
"Merges two sorted collections into one sorted sequence
using comparator"
[cmp left-coll right-coll]
(loop [[lh & lt :as lc] left-coll
[rh & rt :as rc] right-coll
out []]
(cond
(empty? lc) (concat out rc)
(empty? rc) (concat out lc)
@lbeschastny
lbeschastny / extract-unzipsfx
Created October 23, 2015 12:56
Extract extract-unzipsfx binary from 7z sfx archive (using 7z archive it was built from)
#!/bin/bash
if [ "$#" -lt 2 ]; then
echo ""
echo "Usage: extract-unzipsfx <SFX_EXE_PATH> <7Z_ARCHIVE_PATH>"
echo ""
exit 1
fi
head -c $(expr `wc -c < $1` - `wc -c < $2`) $1
@lbeschastny
lbeschastny / Main.sublime-menu
Last active August 29, 2015 14:26
Babel integration for Node.js SublimeREPL
[
{
"id": "tools",
"children":
[{
"caption": "SublimeREPL",
"mnemonic": "r",
"id": "SublimeREPL",
"children": [{
"command": "repl_open",
(defn flatten-bfs [{:keys [attrs content]}]
(loop [ret []
queue (into clojure.lang.PersistentQueue/EMPTY content)]
(if (seq queue)
(let [{attrs :attrs children :content} (peek queue)]
(recur (if (nil? (:v attrs))
ret
(conj ret (:v attrs)))
(into (pop queue) children)))
ret)))
@lbeschastny
lbeschastny / muller.clj
Created May 26, 2015 20:15
Рекуррентное соотношение Мюллера: проблемы с округлением чисел с плавающей точкой - http://habrahabr.ru/post/258483/
(defn f [y z]
(- 108 (/ (- 815 (/ 1500 z)) y)))
(defn muller [x0 x1]
(->> [x0 x1]
(iterate (fn [[a b]] [b (f b a)]))
(map first)))
(-> (muller 4 17/4)
(nth 100)