Skip to content

Instantly share code, notes, and snippets.

@jquery404
jquery404 / gist:2191558
Created March 25, 2012 05:38
Animated Scroll to Div
var goToByScroll= function(id){
$('html,body').animate({scrollTop: $("#"+id).offset().top},'slow');
return false;
}
@jquery404
jquery404 / gist:2191565
Created March 25, 2012 05:40
Fun with KeyCode
$('#searchbox input').bind('keydown', function(e) {
var code = (e.keyCode ? e.keyCode : e.which);
if(e.shiftKey){
$('.dialpad').append('<span class="dial">Shift</span>\n');
event.preventDefault();
}else if(e.altKey){
$('.dialpad').append('<span class="dial">Alt</span>\n');
event.preventDefault();
}else if(e.ctrlKey){
@jquery404
jquery404 / gist:2191576
Created March 25, 2012 05:44
Progressbar with BG-hack
(function($){
// bgImgPos hack
if(!document.defaultView || !document.defaultView.getComputedStyle){ // IE6-IE8
var oldCurCSS = $.curCSS;
$.curCSS = function(elem, name, force){
if(name === 'background-position'){
name = 'backgroundPosition';
}
if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
return oldCurCSS.apply(this, arguments);
@jquery404
jquery404 / gist:2191577
Created March 25, 2012 05:46
Progressbar without BG
(function($){
// Progressbar plugins
$.fn.progBar=function(p){
var Show = (p.labelShow==undefined) ? 'false' : p.labelShow;
var type = (p.type==undefined) ? '' : p.type;
var interval = (p.interval==undefined) ? 1500 : p.interval;
$(this).addClass('progressbar-value progress-header');
$(this).animate({'width' : p.progress + '%'}, interval);
if(Show == true)
$(this).prev('label').html(p.progress + type);
@jquery404
jquery404 / 0_reuse_code.js
Created August 29, 2014 21:23
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
public function uploadFile()
{
$qfilesCount = count($_FILES['quesFiles']['name']);
$afilesCount = count($_FILES['ansFiles']['name']);
$quesImg = array();
$ansImg = array();
for($i = 0; $i < $qfilesCount; $i++)
{
if(!empty($_FILES['quesFiles']['name'][$i]))
@jquery404
jquery404 / Time Loop.js
Last active May 16, 2018 03:42
Loop from start time to end time and returns array of times [8:00AM, 8:30AM, 9:00AM, .....]
$scope.selectedInterval = 30;
$scope.updateTimeInterval = function()
{
var startTime = 8;
var endTime = 13;
var tt = startTime*60; // start at 8am
var ap = ['AM', 'PM'];
//loop to increment the time and push results in array
<select
class="form-control"
ng-options="sub.employee_id as [sub.employee_name_first,sub.employee_name_last].join(' ') for sub in selectedSubject.teacher"
ng-model="selectedTeacher">
</select>
@jquery404
jquery404 / POST.js
Last active July 5, 2018 10:58
Angular HTTP Post
$http({
method: 'POST',
url: 'ws/ws_assignment_post.php',
data: $.param(reqdata),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).then(function (response) {
var data = response.data;
if (data.status === 0) {
window.location.href = "/assignments.php";
}
@jquery404
jquery404 / Distance.sql
Created July 6, 2018 06:26
Here's the SQL statement that will find the closest 20 locations that are within a radius of 25 miles to the 37, -122 coordinate. It calculates the distance based on the latitude/longitude of that row and the target latitude/longitude, and then asks for only rows where the distance value is less than 25, orders the whole query by distance, and l…
SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) )
* cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin(radians(lat)) ) ) AS distance
FROM markers
HAVING distance < 25
ORDER BY distance
LIMIT 0 , 20;