Skip to content

Instantly share code, notes, and snippets.

@yphastos
yphastos / SortFilesInFolderByYearMonth.ps1
Last active January 27, 2022 15:57
Sort files in folders by year/month
<#
Original from:
https://www.thomasmaurer.ch/2015/03/move-files-to-folder-sorted-by-year-and-month-with-powershell/
Sort files inside a folder and move them to YYYY/MM folders.
#>
@yphastos
yphastos / change_collate.sql
Created September 1, 2017 21:15
cambiar character set y collation de tablas en mysql
/*
cambiar character set y collation de tablas en mysql
nota, al parecer HeidiSQL tiene un bug, tal que al seleccionar la default collation a utf8_unicode_ci, las se cambia la tabla pero no las columnas,
si se usa la opcion "convert data" (un checkbox), cambia las columnas a utf8_unicode_ci, pero la tabla la deja como utf8_general_ci
para evitar eso, mejor usar el siguiente comando por tabla:
ref: http://georgepavlides.info/convert-all-tables-in-a-mysql-database-to-utf8_general_ci/
// nota que en la pagina viene a utf8_general_ci, pero es igual usando utf8_unicode_ci
@yphastos
yphastos / _array_keys_lower.php
Last active December 18, 2017 20:40
convert array keys to lowercase
// just for fun, because there already is a native function:
// array array_change_key_case( array $array [, int $case = CASE_LOWER ] ) // || CASE_UPPER
function _array_keys_lower($datos){
// convertir keys de MAY a min
foreach($datos as $k => $v){
if($k == 0){
$cols = array_keys($v);
// pr($cols,"cols");
$Mm = array();
@yphastos
yphastos / equalPairOfBits.java
Last active May 20, 2024 23:44
equal Pair Of Bits
int equalPairOfBits(int n, int m) {
return Integer.lowestOneBit(~(n^m)) ;
}
int equalPairOfBits(int n, int m) {
return (n^=~m)&-n ;
}
int equalPairOfBits(int n, int m) {
return ((n^~m)|((n^~m)-1)) - ((n^~m)-1) ;
@yphastos
yphastos / equalPairOfBits.js
Last active March 7, 2019 00:52
equal Pair Of Bits
function equalPairOfBits(n, m) {
return n + m + 1 & ~m - n ;
}
function equalPairOfBits(n, m) {
return ~(n ^= m) & -~n;
}
function equalPairOfBits(n, m) {
return ~(n ^= m) & -~n;
@yphastos
yphastos / equalPairOfBits.php
Last active March 7, 2019 00:53
equal Pair Of Bits
// ok:
// nota que el codigo es identico a el ejercicio 'different Rightmost Bit', simplemente cambiando la condicion del if
function equalPairOfBits($n, $m) {
return call_user_func(function($n,$m){
$na = str_split(strrev(str_pad(decbin($n),32,'0',STR_PAD_LEFT)));
$ma = str_split(strrev(str_pad(decbin($m),32,'0',STR_PAD_LEFT)));
for($i = 0; $i <32; $i++){
if($na[$i] == $ma[$i]){
return pow(2,$i);
}
@yphastos
yphastos / falseCases.php
Last active September 28, 2017 20:19
false Cases
// false cases
$a = array();
$s = "";
$s0 = "0"; // en php es false (por representar un 0), pero en otros lenguajes puede variar, e.g. en javascript se castea como true (por ser cadena no vacia)
$i = 0;
$b = false;
$f = 0.0;
$h = 0x00; // el vardump la reporta como int
$n = null;
@yphastos
yphastos / differentRightmostBit.java
Last active March 7, 2019 00:55
different Rightmost Bit
int differentRightmostBit(int n, int m) {
return (n^=m) & -n ;
}
int differentRightmostBit(int n, int m) {
return Integer.lowestOneBit(n^m) ;
}
@yphastos
yphastos / differentRightmostBit.js
Last active March 7, 2019 00:53
different Rightmost Bit
function differentRightmostBit(n, m) {
return (n^m) & -(n^m);
}
function differentRightmostBit(n, m) {
return (n ^= m) & -n;
}
function differentRightmostBit(n, m) {
return (n ^ m) & (~(n ^ m) + 1);
@yphastos
yphastos / differentRightmostBit.php
Last active March 7, 2019 00:51
different Rightmost Bit
// DDD:
function differentRightmostBit($n, $m) {
return call_user_func(function($n,$m){
$na = str_split(strrev(str_pad(decbin($n),32,'0',STR_PAD_LEFT)));
$ma = str_split(strrev(str_pad(decbin($m),32,'0',STR_PAD_LEFT)));
for($i = 0; $i <32; $i++){
if($na[$i] != $ma[$i]){
return pow(2,$i);
}
}