Skip to content

Instantly share code, notes, and snippets.

View slav123's full-sized avatar

Slawomir Jasinski slav123

View GitHub Profile
@slav123
slav123 / isipinsub.php
Created September 16, 2013 23:37
check if IP is within the mask
<?php
$ipthing = "192.168.1.201";
$ipsubthing = "*.*.*.201";
if(isipinsub ($ipthing, $ipsubthing)) {echo "It's in the subnet."; } else { echo "Nope."; }
#---------------------------------#
#------isipinsub function---------#
@slav123
slav123 / uExtractNumberFromString.sql
Created September 16, 2013 23:39
Extra numbers from String SQL
select uExtractNumberFromString(mobile) from customer_masterCREATE FUNCTION `uExtractNumberFromString`(in_string varchar(50)) RETURNS INT
NO SQL
BEGIN
DECLARE ctrNumber varchar(50);
DECLARE finNumber varchar(50) default ' ';
DECLARE sChar varchar(2);
@slav123
slav123 / ajax.js
Last active December 23, 2015 05:39
ajax send
$.ajax({
type: "POST",
url: "some.php",
data: {id : menuId},
dataType: "json",
success: function(data){
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status + ' ' + thrownError);
}
@slav123
slav123 / rename-mysql-password.sh
Created September 17, 2013 03:56
rename mysql user password from command line
mysqladmin -u root -p'oldpass' password 'newpass'
@slav123
slav123 / gzip.sh
Created September 17, 2013 03:57
how to check compression on the server
curl -I -H 'Accept-Encoding: gzip,deflate' http://www.example.com/
@slav123
slav123 / is-in-iframe.js
Created September 17, 2013 04:00
how to check if website is within iframe
var isInIFrame = (window.location != window.parent.location) ? true : false;
@slav123
slav123 / smtp-gmail.php
Created September 19, 2013 11:12
send emails via gmail SMTP
<?php
//this functin processes the server return codes and generates errors if needed
function server_parse($socket, $expected_response)
{
$server_response = '';
while (substr($server_response, 3, 1) != ' ')
{
if (!($server_response = fgets($socket, 256)))
echo 'Couldn\'t get mail server response codes. Please contact the forum administrator.', __FILE__, __LINE__;
@slav123
slav123 / spam-test.php
Created September 30, 2013 04:40
check email against stopforumsspam DB
<?php
$spam = file_get_contents('http://www.stopforumspam.com/api?' . http_build_query(array('email' => pun_trim($_POST['req_email1']), 'f' => 'json')));
$json = json_decode($spam);
if ($json->email->appears == 1) {
header("HTTP/1.1 403 Unauthorized", 403);
die("We don't like spammers. Clean up your name at http://www.stopforumspam.com/ ");
}
@slav123
slav123 / xmlsafe.php
Created October 3, 2013 04:52
produce xml safe stuff, same as ENT_XML1 but works with php 5.3
<?php
function xmlsafe($string) {
$replace = array(
'"'=> "&quot;",
"&" => "&amp;",
"'"=> "&apos;",
"<" => "&lt;",
">"=> "&gt;"
);
return strtr($string, $replace);
@slav123
slav123 / loop.less
Created October 7, 2013 02:37
working loop's in LESS
@iterations: 30;
.loopingClass (@iterations);
// helper class, will never show up in resulting css
// will be called as long the index is above 0
.loopingClass (@index) when (@index > 0) {
~.ico@{index} {
// your resulting css