Skip to content

Instantly share code, notes, and snippets.

(function(isNode) {
'use strict';
var Public = function(options) {
// Public() -> new Public()
if (!(this instanceof Public))
<?php
function strtotime_months($num, $timestamp = null) {
$num = (int)$num;
$timestamp = $timestamp ? (int)$timestamp : time();
$result = strtotime("last day of $num month", $timestamp);
var http = require('http'),
url = require('url'),
querystring = require('querystring');
search('filetype:php', 0, handler);
function handler(word, page, addreses) {
var regex = /<b>warning<\/b>:\s*(.*?)<br \/>/mgi,
@yeikos
yeikos / round.sql
Last active December 24, 2015 19:49
SELECT ROUND(2.5); /* 3 */
SELECT ROUND('2.5'); /* 2 */
SELECT ROUND(1.5); /* 2 */
SELECT ROUND('1.5') /* 2 */
SELECT ROUND(0.5); /* 1 */
SELECT ROUND('0.5') /* 0 */
SELECT ROUND(
@yeikos
yeikos / substr-vs-slice.js
Created September 7, 2013 06:01
JavaScript tips
'string'.substr(-2); // 'ng' (IE <= 9 returns 'string')
'string'.slice(-2); // 'ng' (all browsers)
guess(0, 255, function(num, query) {
query(confirm('x > ' + num));
}, function(num) {
document.write('Number is ' + num);
});
@yeikos
yeikos / timestamp.js
Last active December 12, 2015 04:19
Javascript tips
// Timestamp
parseInt(new Date()/1000); // 1316009556
str2argv( 'name(password), long(8, 16), error(Password incorrect)' );
// { "name": ["password"], "long": [8, 16], "error": ["Password incorrect"] }
str2argv( 'one(hello), two(8.698), three( false , "9.6" , 5,), one(world)' );
// { "one": ["world"], "two": [8.698], "three": [false, "9.6", 5, null] }
str2argv( 'numbers(5 , 8)' )['numbers']; // [5, 8]
str2argv( 'nullnumber(,6)' )['nullnumber']; // [null, 6]
str2argv( 'nullnumber( ,6)' )['nullnumber']; // [null, 6]
str2argv( 'null( )' )['null']; // [null]
// Desplazar array
var x = ['a', 'b', 'c', 'd'];
x.push(x.shift()); // ['d', 'b', 'c', 'a']
// Último elemento
var x = 'a,b,c,d';
x.split(',').pop(); // d