Skip to content

Instantly share code, notes, and snippets.

View Ivshti's full-sized avatar
🐊
.

Ivo Georgiev Ivshti

🐊
.
View GitHub Profile
$(document).ready(function()
{
pagesPositions = [];
$(".pagenumber").each(function()
{
pagesPositions.push(this.offsetTop);
});
});
@Ivshti
Ivshti / gist:1570498
Created January 6, 2012 12:58
Crappy code
/* Loads the user data and executes callback() ; also executes it (but with no userData passed) if failed */
loadUserData = function(argsDict, userID, callback)
{
var installationName = argsDict.Installation || "main";
if (!userDataCache[userID])
userDataCache[userID] = new Object();
/* Checks if the entry is cached */
@Ivshti
Ivshti / gist:1654696
Created January 22, 2012 00:20
Simple text search
/* A very simple text search algorithm */
var calcRelevance = function(app)
{
/* Constants */
var KeyPriority = 2, posImportance=2, fillImportance = 1;
var rel = 0;
/* Apply the action in every one of these keys of the app; at the beginning of the cycle, increment the priority
* which means that the further the key is in this array, the more priority it gets (Name is the most important) */
{
"name": "uspehite",
"scripts": {
"start": "./website-server.js"
},
"version": "0.0.0-6",
"engines": {
"node": "0.6.x"
},
"subdomain": "uspehite2",
Array.prototype.sum = function() { var s = 0; for (var i=0; i!=this.length; i++) s+=this[i]; return s; }
function equi ( A ) {
for (var i=0; i!=A.length ;i++)
{
var sumOne = A.slice(0,i).sum(),
sumTwo = A.slice(i+1).sum();
if (sumOne == sumTwo)
return i;
}
return -1;
var digitCount = 10,
max = Math.pow(10, digitCount),
placeholder = [];
for (var i=0; i!=digitCount; i++) placeholder+="0";
for (var i=0; i!=max; i++) tryCombo(placeholder.slice(i.toString().length) + i.toString());
function tryCombo(c) { console.log(c); }
var peersByCountry = data.peers.map(function(peer)
{
var country = getCountry(peer.ip),
loc = countryLoc[country.country_code.toLowerCase()];
country.peer = peer;
if (!loc)
{
console.error("no location for ",country);
country.proximity = 99;
@Ivshti
Ivshti / gist:9628342
Created March 18, 2014 20:05
torrentDownload via peer-wire-protocol
var http = require("http"),
zlib = require("zlib"),
DHT = require("bittorrent-dht"),
net = require("net"),
hat = require("hat"),
bncode = require("bncode"),
async = require("async"),
wire = require("peer-wire-protocol");
var noop = function() {};
#include <node.h>
#include <v8.h>
using namespace v8;
char* buf;
const unsigned size = 400*400;
void GetVideoFrame(const v8::FunctionCallbackInfo<Value>& args)
{