Skip to content

Instantly share code, notes, and snippets.

@yphastos
yphastos / ajas.js
Last active March 26, 2019 18:57
simple ajax with json response
$.ajax({
url:"someUrl.php",
// async:false, // dependera del caso,
dataType:"json", // aqui indico que ya es json
type:'POST',
success:function(res) {
if(res.estatus){
// todo bien, proseguir
}
@yphastos
yphastos / gist:a1809b654de9702811d3a09a66cf82a3
Last active November 9, 2020 13:57
PHP - Redirect with POST data
public static function redirect_post($url,$params){
$html = "";
$html.= '<!doctype html>
<html>
<head>
<script type="text/javascript" language="JavaScript" src="lib/js/jquery-1.8.3.js"></script>
<script>
$(function(){
$("#redirect_form").submit();
});
@yphastos
yphastos / 0_reuse_code.js
Created November 9, 2016 23:38
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@yphastos
yphastos / regex reference
Last active March 7, 2019 00:55
regex reference
// lineas sin comentar
// funcion pr( sin comentar:
// para NPP N++ Notepad++
^(?:(?!//).)*?\Kpr\(
// para Netbeans:
@yphastos
yphastos / each.js
Created May 22, 2017 16:29
jQuery each
// jquery .each
ref: http://api.jquery.com/jquery.each/
jQuery.each( array, callback(index, value) )
jQuery.each( object, callback(key, value) )
// nota que la funcion
$.each()
// puede iterar sobre cualquier coleccion (array o objeto), y NO ES IGUAL a
$(selector).each()
// el cual se usa para iterar SOLO en objetos jQ
@yphastos
yphastos / secondRightmostZeroBit.php
Last active March 7, 2019 00:55
get second rightmost 0 bit as int
function secondRightmostZeroBit($n) {
return ~($n | ($n+1)) & (($n | ($n+1))+1);
}
@yphastos
yphastos / secondRightmostZeroBit.js
Last active March 7, 2019 00:55
second Rightmost Zero Bit
function secondRightmostZeroBit(n) {
return ~(n |= -~n) & -~n;
}
function secondRightmostZeroBit(n) {
return ~(n | n + 1) & (n | n + 1) + 1;
}
@yphastos
yphastos / secondRightmostZeroBit.java
Last active March 7, 2019 00:55
second Rightmost Zero Bit
int secondRightmostZeroBit(int n) {
return ~(n|(n+1)) & ((n|(n+1))+1) ;
}
int secondRightmostZeroBit(int n) {
return (~n) & ((n | ((~n) & (n+1))) +1);
}
@yphastos
yphastos / secondRightmostZeroBit
Last active March 7, 2019 00:55
secondRightmostZeroBit
int secondRightmostZeroBit(int n)
{
return ~(n|=n+1) & -~n ;
}
@yphastos
yphastos / swapAdjacentBits.js
Last active March 7, 2019 00:53
swap Adjacent Bits
function swapAdjacentBits(n) {
return ((n & 0xaaaaaaaa) >> 1) | ((n & 0x55555555) << 1);
}
function swapAdjacentBits(n) {
return x = 2863311530, n/2 & x/2 | 2*n & x;
}
function swapAdjacentBits(n) {
return (n >> 1 & 0x55555555) | (n << 1 & 0xAAAAAAAA) ;