Skip to content

Instantly share code, notes, and snippets.

@calibr
calibr / LevelDbPersistence.js
Created July 30, 2019 22:30
yjs v13(refactored) level db persistence
import level = require('level')
import * as encoding from 'lib0/dist/encoding'
import * as decoding from 'lib0/dist/decoding'
import * as syncProtocol from 'y-protocols/dist/sync.js'
import * as authProtocol from 'y-protocols/dist/auth.js'
import { createMutex } from 'lib0/dist/mutex.js'
const mux = createMutex()
function getEmptyEncodedStateVector() {
@calibr
calibr / make_string_occurrences_bold.js
Created April 30, 2016 21:16
Make all occurrences of specific string bold
// has been got from http://stackoverflow.com/a/3410557/3097116
function getIndicesOf(searchStr, str, caseSensitive) {
var startIndex = 0, searchStrLen = searchStr.length;
var index, indices = [];
if (!caseSensitive) {
str = str.toLowerCase();
searchStr = searchStr.toLowerCase();
}
while ((index = str.indexOf(searchStr, startIndex)) > -1) {
indices.push(index);
var http = require("http");
var domain = require("domain");
function log() {
var args = [].slice.call(arguments);
args.unshift(process.uptime()+"s:");
console.log.apply(console, args);
}
var agent = new http.Agent({
@calibr
calibr / gist:ee5031e9a7863725a52d
Created October 31, 2014 03:10
parse playstore app image
<?php
function grab($url) {
$page = file_get_contents($url);
if(preg_match('@<div class="cover-container">(.+?)</div>@', $page, $m)) {
if(preg_match('@src\s*=\s*"(.+?)"@', $m[1], $m)) {
return $m[1];
}
}
return null;