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 / numlock_on.sh
Last active January 17, 2016 09:24
Enable NumLock on Ubuntu by default
sudo apt-get -y install numlockx
sudo sed -i 's|^exit 0.*$|# Numlock enable\n[ -x /usr/bin/numlockx ] \&\& numlockx on\n\nexit 0|' /etc/rc.local
# http://askubuntu.com/questions/155679/how-to-enable-numlock-at-boot-time-for-login-screen
@danielgindi
danielgindi / list_files_group_by_ext.sh
Last active April 3, 2016 14:12
(Linux) List file counts grouped by file extension
find ./ -maxdepth 1 -type f | grep -E ".*\.[a-zA-Z0-9]*$" | sed -e 's/.*\(\.[a-zA-Z0-9]*\)$/\1/' | sort | uniq -c | sort -n
@danielgindi
danielgindi / exec_fun_w_args_isolated.js
Created September 18, 2016 12:50
JS: Execute function given name and args - in an isolate scope
var execIsolated = (function () {
var exec = function () {
arguments[0](arguments[1]);
};
return function (funcname, args) {
args = args || [];
@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) +
@danielgindi
danielgindi / syntax_convert.js
Last active March 6, 2017 08:12
Convert syntax between languages
/* Note:
This is not meant for translating real code between languages.
Only for basic syntax translation, to get you started with a skeleton,
before doing line-by-line manually
*/
var Converter = {
curlifyWhitespace: function (code) {
@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 / 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 / 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 / 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 / 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,