Skip to content

Instantly share code, notes, and snippets.

View swape's full-sized avatar
😎

Alireza Balouch swape

😎
  • Mjolnir Media AS
  • Kongsberg, Norway
  • 09:52 (UTC +02:00)
View GitHub Profile
@swape
swape / proxy.php
Created January 15, 2014 12:13
ssl proxy to show non ssl images in ssl env.
<?php
// https://mysecureserver.com/path_to_this_script/?url=[base64 encoded image link]*
$file = base64_decode(@$_GET['url']);
$aFile = end(explode('.' , $file));
if($aFile == 'jpg' or $aFile == 'jpeg'){
header('Content-Type: image/jpeg');
}elseif($aFile == 'png'){
header('Content-Type: image/png');
}elseif($aFile == 'gif'){
@swape
swape / scrollLoad.js
Created January 8, 2014 12:35
This script calls a function when scrolling 90px from end of the screen.
var mLock = true;
$(window).scroll(function(){
if (document.body.scrollHeight <= document.body.scrollTop + window.innerHeight + 90 ){
if(mLock){
mLock = false;
doSomeFunction();
}
}
});
@swape
swape / refreshLikes.js
Last active January 2, 2016 14:19
Updating facebook like buttons when loaded via ajax.
try{ FB.XFBML.parse(); }catch(ex){}
@swape
swape / spinner.html
Last active December 30, 2015 08:19
CSS Spinner
<style>
.spin {
border: 8px solid rgba(0, 0, 0, .1);
border-top: 8px solid rgba(100, 0, 0, .4);
border-radius: 100%;
height: 20px;
width: 20px;
animation: rot 1s infinite linear;
}
@swape
swape / gist:5684498
Created May 31, 2013 11:55
It takes url's in a plain text and turn it to html link.
<?php
function formatUrlsInText($strInput){
$strInput = ereg_replace( "www\.", "http://www.", $strInput );
$strInput = ereg_replace( "http://http://www\.", "http://www.", $strInput );
$strInput = ereg_replace( "https://http://www\.", "https://www.", $strInput );
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
preg_match_all($reg_exUrl, $strInput, $matches);
$usedPatterns = array();
foreach($matches[0] as $pattern){
@swape
swape / gist:5618896
Created May 21, 2013 10:38
Limiting an input field to only accept numbers
function validate(evt) {
var theEvent = evt || window.event;
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode( key );
var regex = /[0-9]|\./;
if( !regex.test(key) ) {
theEvent.returnValue = false;
if(theEvent.preventDefault) theEvent.preventDefault();
}
}
@swape
swape / gist:5618835
Created May 21, 2013 10:24
Limiting textarea content
var intMax = 140;
$('textarea').live('keydown blur' , function(){
var innerhtml = $(this).val();
if(innerhtml.length >= intMax ){
$(this).val( innerhtml.substring(0,intMax) );
}
});
@swape
swape / gist:5618819
Created May 21, 2013 10:21
Facebook share function
function fb_share(url,tittel) {u=url;t=tittel;window.open('https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}
@swape
swape / gist:5618813
Created May 21, 2013 10:20
Mobile detector
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ){
// do something for mobile browsers
}
@swape
swape / gist:5618795
Created May 21, 2013 10:16
Validating email adr
function validateEmail(e){var t=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;return t.test(e);}
if(validateEmail($('#emailinput').val())){
// do something
}