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: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: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: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>
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{
<?php
class a
{
var $arr = array();
function set()
{
$args = func_get_args();
$last = array_pop( $args );
@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();
@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:5005274
Last active December 14, 2015 01:19
recurse array function
recurse_func = function(arr, callback, delay) {
if (typeof(callback) == "function") {
delay = delay || 200;
var self = arr, idx = 0;
setInterval(function() {
callback(self[idx], idx);
idx = (idx+1 < self.length) ? idx+1 : 0;
}, delay);
}
@asjustas
asjustas / gist:5247134
Created March 26, 2013 17:03
Change open files limit centos
$ ulimit -n
4096
$ ulimit -n 8192
bash: ulimit: open files: cannot modify limit: Operation not permitted
$ sudo bash
# ulimit -n
4096
# ulimit -n 8192
# su - normaluser
$ ulimit -n
@asjustas
asjustas / gist:5363442
Created April 11, 2013 13:38
websocket basic
var connection = new WebSocket('ws://127.0.0.1:1337');
connection.onopen = function () {
// first we want users to enter their names
input.removeAttr('disabled');
status.text('Choose name:');
};
connection.onerror = function (error) {
// just in there were some problems with conenction...