Skip to content

Instantly share code, notes, and snippets.

View asjustas's full-sized avatar

Justas asjustas

  • Vilnius, Lietuva
View GitHub Profile
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
var Example = window.Example || (function() {
var self = {};
// This method:
self.Update = function() {
var self = {};
self.itemcurrency = function() {
}
@asjustas
asjustas / gist:2421893
Created April 19, 2012 15:49
simple php file upload
<?php
//patikriname ar vartotojas ákelia bylà
if ($_FILES['byla']) {
//tikriname ar ákelta byla yra iðtiesø paveikslëlis
if (exif_imagetype($_FILES['byla']['tmp_name'])) {
//jei paveikslëlis toliau tikriname ar tinkamas tipas
$pav_attr = getimagesize($_FILES['byla']['tmp_name']);
$width = $pav_attr[0];
$height = $pav_attr[1];
$type = $pav_attr['mime'];
@asjustas
asjustas / redis-counters.js
Created April 20, 2012 21:04 — forked from dvbportal/redis-counters.js
Storing Counters In Redis
// Additional code in node-http-proxy.js
var crypto = require('crypto');
var redis = require('redis');
var client = redis.createClient(config.opt.redis_port, 'cloudno.de');
client.auth(config.opt.redis_auth, function(result) {
util.log("Redis authenticated.");
})
@asjustas
asjustas / gist:3672782
Created September 8, 2012 08:28
Simple function to minimize inline js
<?php
$code = 'js code';
$replace = array(
'#\'([^\n\']*?)/\*([^\n\']*)\'#' => "'\1/'+\'\'+'*\2'", // remove comments from ' strings
'#\"([^\n\"]*?)/\*([^\n\"]*)\"#' => '"\1/"+\'\'+"*\2"', // remove comments from " strings
'#/\*.*?\*/#s' => "", // strip C style comments
'#[\r\n]+#' => "\n", // remove blank lines and \r's
'#\n([ \t]*//.*?\n)*#s' => "\n", // strip line comments (whole line only)
'#([^\\])//([^\'"\n]*)\n#s' => "\\1\n",
@asjustas
asjustas / gist:4085461
Created November 16, 2012 08:27
scroll to element
$('html,body').animate({scrollTop: $("#block_"+block).offset().top}, 'slow');
@asjustas
asjustas / gist:4085484
Created November 16, 2012 08:31
go top
$('html, body').animate({ scrollTop: 0 }, 'slow');
@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();
}
@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: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]