Skip to content

Instantly share code, notes, and snippets.

View danielgindi's full-sized avatar

Daniel Cohen Gindi danielgindi

  • Self Employed, CTO at eyedo fielding technologies ltd.
  • Israel
View GitHub Profile
@danielgindi
danielgindi / MySql_Partitioning.sql
Last active November 5, 2023 10:02
MySql automatic partitioning by RANGE of month/day, no external scripts
DELIMITER $$
DROP TABLE IF EXISTS _partitioned_tables; $$
CREATE TABLE IF NOT EXISTS `_partitioned_tables` (
`owner_name` VARCHAR(100) NOT NULL,
`table_name` VARCHAR(100) NOT NULL,
`column_name` VARCHAR(100) NOT NULL,
`mode` ENUM('day', 'month'),
`future_partitions` INT NOT NULL,
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 February 24, 2024 01:44
Bulk delete Bitbucket LFS files
(() => {
// 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 March 25, 2019 08:17
Patch to add a "sourceless" feature to node.js v11.x
--- 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 March 25, 2019 08:16
Patch to add a "sourceless" feature to node.js v10.x
--- 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 November 1, 2018 14:19
Callout view for React Native
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 November 21, 2017 06:44
Generate a list of the common-denominator CIDR IP ranges from a list of IPs
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 July 12, 2017 10:12
CSS minifier (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 March 14, 2017 06:01
Rename database in Mysql
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 November 15, 2016 12:55
Find the color (out of an array of colors) that is most distant (brightness-wise) to the target color.
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) +