Skip to content

Instantly share code, notes, and snippets.

@guisehn
guisehn / multiple-files-remove-prefix.md
Created February 4, 2020 20:28
Remove prefix from multiple files in Linux console

Bash

for file in prefix*; do mv "$file" "${file#prefix}"; done;

The for loop iterates over all files with the prefix. The do removes from all those files iterated over the prefix.

Here is an example to remove "bla_" form the following files:

bla_1.txt
bla_2.txt
arr=[]
len=4
for (sub=0; sub<=0; sub++) {
for (i = 0; i < Math.pow(2,len); i++) {
for (j = 0; j < Math.pow(2,len); j++) {
let obj = {
sub: sub,
a: i.toString(2).padStart(len,'0'),
b: j.toString(2).padStart(len,'0'),
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org
root = true
[*]
# Change these settings to your own preference
var arr = {"0:0":"ffffff","0:1":"ffffff","0:2":"ffffff","0:3":"ffffff","0:4":"ffffff","0:5":"ffffff","0:6":"ffffff","0:7":"ffffff","0:8":"ffffff","0:9":"ffffff","0:10":"ffffff","0:11":"ffffff","0:12":"ffffff","0:13":"ffffff","0:14":"ffffff","0:15":"ffffff","0:16":"ffffff","0:17":"ffffff","0:18":"ffffff","0:19":"ffffff","0:20":"ffffff","0:21":"ffffff","0:22":"ffffff","0:23":"ffffff","0:24":"ffffff","0:25":"ffffff","0:26":"ffffff","0:27":"ffffff","0:28":"ffffff","0:29":"ffffff","0:30":"ffffff","0:31":"ffffff","0:32":"ffffff","0:33":"ffffff","0:34":"ffffff","0:35":"ffffff","0:36":"ffffff","0:37":"ffffff","0:38":"ffffff","0:39":"ffffff","0:40":"fffeff","0:41":"fffeff","0:42":"ffffff","0:43":"ffffff","0:44":"ffffff","0:45":"fffeff","0:46":"fffeff","0:47":"fffeff","0:48":"ffffff","0:49":"fffdff","0:50":"f9f5f2","0:51":"cfbda7","1:0":"ffffff","1:1":"ffffff","1:2":"ffffff","1:3":"ffffff","1:4":"ffffff","1:5":"ffffff","1:6":"ffffff","1:7":"ffffff","1:8":"ffffff","1:9":"ffffff","1:10":"ffffff","1:11":"ffffff","1:12":"f
@guisehn
guisehn / gist:6648c8fdcd1102a22a22
Last active June 2, 2021 11:08 — forked from wrburgess/gist:5528649
Backup Heroku Postgres database and restore to local database

Grab new backup

Command: heroku pg:backups capture -a [app_name]

Download

Command: curl -o latest.dump `heroku pg:backups public-url -a [app_name]`

Restore backup dump into local db

@guisehn
guisehn / cep.php
Created August 25, 2012 18:15
CEP (PHP)
<?php
function cep_dados($cep)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.buscacep.correios.com.br/servicos/dnec/consultaLogradouroAction.do');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
@guisehn
guisehn / gist:3276302
Last active April 3, 2024 13:24
Validar CNPJ (PHP)
<?php
function validar_cnpj($cnpj)
{
$cnpj = preg_replace('/[^0-9]/', '', (string) $cnpj);
// Valida tamanho
if (strlen($cnpj) != 14)
return false;
@guisehn
guisehn / gist:3276015
Created August 6, 2012 16:13
Validar CPF (PHP)
<?php
function validar_cpf($cpf)
{
$cpf = preg_replace('/[^0-9]/', '', (string) $cpf);
// Valida tamanho
if (strlen($cpf) != 11)
return false;
@guisehn
guisehn / csrf.php
Created July 22, 2012 00:00
Simple class for CSRF protection
<?php
abstract class CSRF
{
const SESSION_NAME = 'nomedosite_csrf_token';
const FIELD_NAME = 'nomedosite_csrf_check';
private static function set_session()
{
if (!isset($_SESSION[self::SESSION_NAME]))