Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
yeah, that

B. Agustín Amenábar Larraín baamenabar

:octocat:
yeah, that
View GitHub Profile
@baamenabar
baamenabar / move.php
Created Sep 25, 2014
PHP move all files and folders from one directory to a new directory
View move.php
<?php
$dir = ".";//"path/to/targetFiles";
$dirNew = "viejo2014";//path/to/destination/files
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
echo '<br>Archivo: '.$file;
//exclude unwanted
if ($file=="move.php")continue;
@baamenabar
baamenabar / FlieList-mock-creator.ts
Created Sep 13, 2020
Create a mock FileList to test file upload components.
View FlieList-mock-creator.ts
/** list of mock File elements to pass the input[file] */
export function getBrowsedFiles(): FileList {
return fileListFromArray([
mockFileCreator({ name: 'file-one.png', type: 'image/png', size: 234 * 1000 }),
mockFileCreator({ name: 'file-two.gif', type: 'image/gif', size: 56 * 1000 }),
]);
}
export function mockFileCreator({
name = 'file.txt',
@baamenabar
baamenabar / index.php
Last active May 3, 2020
PHP List images in folder
View index.php
<?php
/*
list all the files with extension nn on a folder
the first parameter of glob is a regex to match files.
you can do:
path_to_dir/*.html
to select all the .html files in the path_to_dir folder
*NOTE:* the regex on glob is case sensitive
@baamenabar
baamenabar / rename-with-md5sum.sh
Last active Jan 7, 2020
in shell bash: Read a file, get the md5 checksum, save it in a variable, make a copy of the file with the hash,
View rename-with-md5sum.sh
#!/bin/bash
# http://stackoverflow.com/questions/3679296/only-get-hash-value-using-md5sum-without-filename
md5HASH=($(md5sum www/app/js/bundle.js| cut -d ' ' -f 1))
cp www/app/js/bundle.js www/app/js/bundle-$md5HASH.js;
# store in variable in file
echo "<?php define('HASH_EXT', '$md5HASH'); ?>" > www/app/inc/hash-bundle.php;
@baamenabar
baamenabar / install_docker_and_jenkins.sh
Last active Oct 15, 2019
Installing Docker, setting it up for Jenkins, and installing Jenkins.
View install_docker_and_jenkins.sh
#!/bin/bash
# Copied from: https://raw.githubusercontent.com/wardviaene/jenkins-course/master/scripts/install_jenkins.sh
# Updated with : https://docs.docker.com/install/linux/docker-ce/ubuntu/
# this script is only tested on ubuntu xenial and bionic
# sudo is only if you are not on root (you should not be on root)
# Uninstall previous versions of docker
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
@baamenabar
baamenabar / obtener_costo_envio_paquete.php
Last active Mar 31, 2019 — forked from nikoskip/valores_chilexpress.php
Obtener costos de envío por Chilexpress, usando el formulario de cálculo que tienen ellos. A falta de un API, hay que hacerse uno. Todo mérito a @nikoskip
View obtener_costo_envio_paquete.php
<?php
/**
* Una simple función para obtener los costos de envío de un paquete mediante Chilexpress.
* Como única dependencia se necesita de la liberia PHP Simple HTML DOM Parser: http://simplehtmldom.sourceforge.net/
*
* Para poder comunicarse con Chilexpress, se debe tener la lista de todas las comunas que ellos utilizan y el código
* que le asignan a cada una. En este archivo, al final, podrás encontrar el listado, el cual podrás parsear fácilmente
*/
@baamenabar
baamenabar / flyimg-up.sh
Last active Jan 7, 2019
Don't forget how to build and start Flyimg in windows 10 home environment with Cmder (conEmu)
View flyimg-up.sh
# Windows only: Don't forget how to build and start Flyimg in windows 10 home environment with Cmder (conEmu)
# Must have virtualbox installed, ideally through docker toolbox
# do this only once
docker-machine create --driver virtualbox default
# all the subsequent times, only this
docker-machine start default
# hook the virtual env to docker
@baamenabar
baamenabar / stat-is-folder-comparison.js
Created Jul 11, 2018
Compare different approaches and node 10.x APIs to stat a directory or folder, and by extension do many fs operations. Includes experiment with fs promises
View stat-is-folder-comparison.js
const fs = require("fs");
const fsPromises = require("fs").promises;
/**
* Util function we will reuse to check if the caught error is simply a "not found" error
*
* @param {*} err
* @returns {boolean}
*/
function isErrorNotFound(err) {
View md5-hash-in-node.js
const fileHash = crypto.createHash('md5').update(fileContents).digest('hex');
@baamenabar
baamenabar / special-char-by-eu-lang.md
Created May 6, 2015
Special caracters by European Language
View special-char-by-eu-lang.md