Skip to content

Instantly share code, notes, and snippets.

View zucchinidev's full-sized avatar
🎯
Focusing

Andrea Zucchini zucchinidev

🎯
Focusing
View GitHub Profile
<div class="col-md-3 col-xs-12">
Sidebar
</div>
<div class="col-md-9 col-xs-12">
Content
</div>
@zucchinidev
zucchinidev / clone.js
Last active October 10, 2016 15:40
Clonado de objeto. Permite el clonado de propiedades creadas mediante sus descriptores.
function clone(obj) {
var ctr = Object.getPrototypeOf(obj).constructor;
return Object.assign(new ctr(), obj);
}
(function() {
'use strict';
var createCookie = function(cookieName, cookieValue) {
var oneDay = 86400;
document.cookie = cookieName + "=" + cookieValue + "; max-age=" + oneDay + "; path=/";
};
var readCookie = function(cookieName) {
var result;
var nameEQ = cookieName + "=";
@zucchinidev
zucchinidev / elements-not-repeated.reduce.js
Last active February 5, 2017 19:22
Reduce Data with Javascript Array#reduce
var films = [{
title: 'El señor de los anillos',
year: 2008,
cast: [
'Christian Bale',
'Heath Ledger',
'Aaron Eckhart',
'Michael Cane',
'Gary Oldman',
'Morgan Freeman'
@zucchinidev
zucchinidev / require.js
Last active August 2, 2017 16:08
A reduced implementation of Require.js
const loadModule = (filename, module, require) => {
const wrappedSrc = `(function(module, exports, require) {
${fs.readFileSync(filename, 'utf8')}
})(module, module.exports, require);`
eval(wrappedSrc)
}
const require = (moduleName) => {
console.log(`Require invoked for módule: ${moduleName}`)
const id = require.resolve(moduleName)
@zucchinidev
zucchinidev / repare.sh
Last active September 15, 2017 08:36
Git: “Corrupt loose object”
# Create a backup of the corrupt directory:
cp -R foo foo-backup
# Make a new clone of the remote repository to a new directory:
git clone git@www.mydomain.de:foo foo-newclone
# Delete the corrupt .git subdirectory:
rm -rf foo/.git
# Move the newly cloned .git subdirectory into foo:
mv foo-newclone/.git foo
# Delete the rest of the temporary new clone:
rm -rf foo-newclone
@zucchinidev
zucchinidev / main.go
Last active October 4, 2017 14:25
Runner: The purpose of the runner package is to show how channels can be used to monitor the amount of time a program is running and terminate the program if it runs too long. This pattern is useful when developing a program that will be scheduled to run as a background task process.
package main
import (
"time"
"log"
"github.com/zucchinidev/runnerWork/runner"
"os"
)
const timeout = 3 * time.Second
@zucchinidev
zucchinidev / main.go
Created October 5, 2017 13:34
The purpose of the work package is to show how you can use an unbuffered channel to create a pool of goroutines that will perform and control the amount of work that gets done concurrently
package main
import (
"log"
"github.com/zucchinidev/work/work"
"sync"
"time"
)
var names = []string{
@zucchinidev
zucchinidev / createBigFile.sh
Created May 31, 2018 15:06
Create a big file with dd command
// newFile 24-25MB
dd if=/dev/urandom of=newfile bs=1M count=24
export class RetryRequest {
private maxRetries: number[];
constructor(private timeout: number, maxRetries = 10) {
this.maxRetries = [...Array(maxRetries)].map((_, i) => i)
}
wait(timeout: number) {
return new Promise((resolve) => setTimeout(() => resolve(), timeout))
}