Skip to content

Instantly share code, notes, and snippets.

View gnzg's full-sized avatar
🎯
Focusing

I. Ginzburg gnzg

🎯
Focusing
View GitHub Profile
@penguinboy
penguinboy / Object Flatten
Created January 2, 2011 01:55
Flatten javascript objects into a single-depth object
var flattenObject = function(ob) {
var toReturn = {};
for (var i in ob) {
if (!ob.hasOwnProperty(i)) continue;
if ((typeof ob[i]) == 'object') {
var flatObject = flattenObject(ob[i]);
for (var x in flatObject) {
if (!flatObject.hasOwnProperty(x)) continue;
@senko
senko / onchange.sh
Last active July 14, 2023 07:54
OnChange - Watch current directory and execute a command if anything in it changes
#!/bin/bash
#
# Watch current directory (recursively) for file changes, and execute
# a command when a file or directory is created, modified or deleted.
#
# Written by: Senko Rasic <senko.rasic@dobarkod.hr>
#
# Requires Linux, bash and inotifywait (from inotify-tools package).
#
# To avoid executing the command multiple times when a sequence of
@dadon
dadon / gist:1231988
Created September 21, 2011 13:10
[JS] Set selection and cursor position in text input
function setInputSelection(input, startPos, endPos) {
if (input.setSelectionRange) {
input.focus();
input.setSelectionRange(startPos, endPos);
} else if (input.createTextRange) {
var range = input.createTextRange();
range.collapse(true);
range.moveEnd('character', endPos);
range.moveStart('character', startPos);
range.select();
@banaslee
banaslee / XGH - en.txt
Last active June 5, 2024 00:29
eXtreme Go-Horse Process
eXtreme Go Horse (XGH) Process
Source: http://gohorseprocess.wordpress.com
1. I think therefore it's not XGH.
In XGH you don't think, you do the first thing that comes to your mind. There's not a second option as the first one is faster.
2. There are 3 ways of solving a problem: the right way, the wrong way and the XGH way which is exactly like the wrong one but faster.
XGH is faster than any development process you know (see Axiom 14).
@paulallies
paulallies / gist:0052fab554b14bbfa3ef
Last active November 12, 2023 23:00
Remove node_modules from git repo
#add 'node_modules' to .gitignore file
git rm -r --cached node_modules
git commit -m 'Remove the now ignored directory node_modules'
git push origin <branch-name>
@schmidt1024
schmidt1024 / svg.js
Created June 3, 2015 13:59
Replace all SVG images with inline SVG using jQuery
/*
* Replace all SVG images with inline SVG
*/
jQuery('img.svg').each(function(){
var $img = jQuery(this);
var imgID = $img.attr('id');
var imgClass = $img.attr('class');
var imgURL = $img.attr('src');
jQuery.get(imgURL, function(data) {
@williamrjribeiro
williamrjribeiro / prefixsum.js
Last active March 19, 2021 10:08
JavaScript Prefix Sum Function
function prefixSum(A) {
var i = 0,
l = A.length,
P = new Array(l),
sum = A[0];
P[0] = sum;
while (++i < l) {
sum += A[i];
@che-wf
che-wf / findeDupes.js
Created July 22, 2016 17:39
This is an efficient approach to finding duplicates in an array or eliminating duplicates from an array.
var a = ["a","a","b","c","c"];
var dupes = a.filter((value,index,self)=>{ return (self.indexOf(value) !== index )});
var cleanArray = a.filter((value,index,self)=>{ return (self.indexOf(value) === index )});
console.log(dupes);
console.log(cleanArray);
@thevangelist
thevangelist / my-component.spec.js
Created August 4, 2016 13:06
The only React.js component test you'll ever need (Enzyme + Chai)
import React from 'react';
import { shallow } from 'enzyme';
import MyComponent from '../src/my-component';
const wrapper = shallow(<MyComponent/>);
describe('(Component) MyComponent', () => {
it('renders without exploding', () => {
expect(wrapper).to.have.length(1);
});
@msmfsd
msmfsd / es7-async-await.js
Last active February 4, 2024 17:38
Javascript fetch JSON with ES7 Async Await
// Async/Await requirements: Latest Chrome/FF browser or Babel: https://babeljs.io/docs/plugins/transform-async-to-generator/
// Fetch requirements: Latest Chrome/FF browser or Github fetch polyfill: https://github.com/github/fetch
// async function
async function fetchAsync () {
// await response of fetch call
let response = await fetch('https://api.github.com');
// only proceed once promise is resolved
let data = await response.json();
// only proceed once second promise is resolved