Skip to content

Instantly share code, notes, and snippets.

View asjustas's full-sized avatar

Justas asjustas

  • Vilnius, Lietuva
View GitHub Profile
@asjustas
asjustas / gist:4986104
Created February 19, 2013 13:56
default function arguments
function foo(a, b)
{
a = typeof a !== 'undefined' ? a : 42;
b = typeof b !== 'undefined' ? b : 'default_b';
...
}
@asjustas
asjustas / gist:4983845
Created February 19, 2013 07:47
Is element in viewport
$.fn.isOnScreen = function(){
var win = $(window);
var viewport = {
top : win.scrollTop(),
left : win.scrollLeft()
};
viewport.right = viewport.left + win.width();
viewport.bottom = viewport.top + win.height();
<?php
class a
{
var $arr = array();
function set()
{
$args = func_get_args();
$last = array_pop( $args );
smart_ajax({
url: document.location.href,
type: 'POST',
data: q,
dataType: 'json',
error: function(){ alert('Error while trying to connect to server') },
success: function(json){
if(json.ok == true){
}else{
@asjustas
asjustas / gist:4538145
Last active December 11, 2015 03:29
Searchable ul list, with result highlight
<style>
.marked{
background-color: #FEE65F;
display: inline-block;
position: relative;
top: -1px;
}
</style>
<script>
@asjustas
asjustas / gist:4205326
Created December 4, 2012 15:45
Open popup in center
function windowOpener(windowHeight, windowWidth, windowName, windowUri)
{
var centerWidth = (window.screen.width - windowWidth) / 2;
var centerHeight = (window.screen.height - windowHeight) / 2;
newWindow = window.open(windowUri, windowName, 'resizable=0,width=' + windowWidth +
',height=' + windowHeight +
',left=' + centerWidth +
',top=' + centerHeight);
@asjustas
asjustas / gist:4168029
Created November 29, 2012 10:20
Box-sizing 100% width textarea
.boxsizingBorder {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
@asjustas
asjustas / gist:4134771
Created November 23, 2012 09:38
Redirect everything to non-www
RewriteBase /
RewriteCond %{HTTP_HOST} !^rankoholic\.com$ [NC]
RewriteRule ^(.*)$ http://rankoholic.com/$1 [R=301,L]
@asjustas
asjustas / gist:4117951
Created November 20, 2012 13:32
Sort before group by
SELECT * FROM
(
select * from `my_table` order by timestamp desc
) as my_table_tmp
group by catid
order by nid desc
@asjustas
asjustas / gist:4085574
Created November 16, 2012 08:47
scrool to top visible
var isVisible = false;
$(window).scroll(function(){
var shouldBeVisible = $(window).scrollTop()>200;
if (shouldBeVisible && !isVisible) {
isVisible = true;
$('#mybutton').show();
} else if (isVisible && !shouldBeVisible) {
isVisible = false;
$('#mybutton').hide();
}