Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Cohen Gindi danielgindi

  • Self Employed, CTO at eyedo fielding technologies ltd.
  • Israel
View GitHub Profile
View LZRW1.js
class LZRW1 {
static #FLAG_BYTES = 4;
static #FLAG_COMPRESS = 0;
static #FLAG_COPY = 1;
static #WORK_MEM_ALLOC = 4 * 4096 + 3;
static #WORKMEM = new Array(LZRW1.#WORK_MEM_ALLOC);
/** @returns {Buffer} */
static compress(/**@type Buffer*/input) {
const WORKMEM = this.#WORKMEM.fill(0);
@danielgindi
danielgindi / delete_bitbucket_lfs_files.js
Last active Jul 12, 2021
Bulk delete Bitbucket LFS files
View delete_bitbucket_lfs_files.js
(() => {
// Run this in Chrome's console, while in Bitbucket's website and logged in
const csrftoken = document.cookie.match(/\bcsrftoken=(.*?)(?:;| |$)/)[1];
const repoName = window.__initial_state__.section.repository.currentRepository.full_name;
const expiry = 1000 * 60 * 60; // Delete only files older than an hour
let page = 1;
function iterateNext() {
fetch(`https://bitbucket.org/${repoName}/admin/lfs/file-management/?iframe=true&spa=0&page=${page}`, {
@danielgindi
danielgindi / node_v11.x_sourceless_script.patch
Last active Mar 25, 2019
Patch to add a "sourceless" feature to node.js v11.x
View node_v11.x_sourceless_script.patch
--- a/deps/v8/include/v8.h
+++ b/deps/v8/include/v8.h
@@ -1564,9 +1564,10 @@ class V8_EXPORT ScriptCompiler {
};
enum CompileOptions {
- kNoCompileOptions = 0,
- kConsumeCodeCache,
- kEagerCompile
+ kNoCompileOptions = 0x00,
@danielgindi
danielgindi / node_v10.x_sourceless_script.patch
Last active Mar 25, 2019
Patch to add a "sourceless" feature to node.js v10.x
View node_v10.x_sourceless_script.patch
--- a/deps/v8/include/v8.h
+++ b/deps/v8/include/v8.h
@@ -1449,12 +1449,13 @@ class V8_EXPORT ScriptCompiler {
enum CompileOptions {
kNoCompileOptions = 0,
- kProduceParserCache,
- kConsumeParserCache,
- kProduceCodeCache,
- kProduceFullCodeCache,
@danielgindi
danielgindi / callout-view.js
Created Nov 1, 2018
Callout view for React Native
View callout-view.js
import React, { Component } from 'react';
import { View, StyleSheet, Text, Image } from 'react-native';
import PropTypes from 'prop-types';
import { TouchableNativeFeedback } from 'react-native';
export default class CalloutView extends Component {
static propTypes = {
onPress: PropTypes.func,
parentLayout: PropTypes.any,
@danielgindi
danielgindi / get_lowest_ip_ranges.js
Created Nov 21, 2017
Generate a list of the common-denominator CIDR IP ranges from a list of IPs
View get_lowest_ip_ranges.js
function getLowestIpRanges(ips) {
let ipRanges = [];
ips.forEach(x => {
let x3 = x.replace(/\d+$/, '');
let x2 = x3.replace(/\d+\.?$/, '');
let x1 = x2.replace(/\d+\.?$/, '');
let ex = ipRanges.filter(y => y == x3 + '0' || y == x2 + '0.0' || y == x1 + '0.0.0');
if (ex.length) return;
@danielgindi
danielgindi / css_minifer.js
Last active Jul 12, 2017
CSS minifier (JS)
View css_minifer.js
var CssMinifier = (function () {
function unescapeString(value) {
// CSS RFC states that the escape character (\) escapes every character to itself,
// except for a variable length hex-digit sequence that is converted to a character by that hex value.
// An escaped hex value can be ended with an optional whitespace ( \t\n).
var out = '';
var quoted = false;
var hexEscapeSeq = '';
@danielgindi
danielgindi / mysql_rename_database.sql
Last active Mar 14, 2017
Rename database in Mysql
View mysql_rename_database.sql
SET SESSION group_concat_max_len = 99999999999;
SET @old_schema_name = 'old_schema';
SET @new_schema_name = 'new_schema';
SELECT GROUP_CONCAT(statement SEPARATOR '')
FROM (
SELECT 'DELIMITER $$\n\n' AS statement
UNION ALL
@danielgindi
danielgindi / get_distant_brightness_color.js
Created Nov 15, 2016
Find the color (out of an array of colors) that is most distant (brightness-wise) to the target color.
View get_distant_brightness_color.js
var getDistantBrightnessColor = (function () {
// Calculate grayscale color (luma) according to ITU-R Recommendation BT. 709
var grayscaleLuma709Color = function(color) {
return Math.round(0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b)
};
var linearDiffColor = function(color1, color2) {
return Math.abs(color1.r - color2.r) +
Math.abs(color1.g - color2.g) +
@danielgindi
danielgindi / exec_fun_w_args_isolated.js
Created Sep 18, 2016
JS: Execute function given name and args - in an isolate scope
View exec_fun_w_args_isolated.js
var execIsolated = (function () {
var exec = function () {
arguments[0](arguments[1]);
};
return function (funcname, args) {
args = args || [];