Skip to content

Instantly share code, notes, and snippets.

View kopiro's full-sized avatar

Flavio Maria De Stefano kopiro

View GitHub Profile
@kopiro
kopiro / php-isset.js
Created June 10, 2011 20:44
The PHP isset foo ported to Javascript
// To use the isset() function to determine the status of x, call isset("x").
function isset(x) {
return typeof(window[x])=="undefined" ? false : true;
}
@kopiro
kopiro / book-ordering-list.c
Created June 12, 2011 18:01
Order a book.txt alphabetically with Lists in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct node* link;
struct node {
char* item;
link next;
link prev;
};
@kopiro
kopiro / write-row-by-seq.c
Created June 14, 2011 14:18
Write row by file in a sequence of row
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_ROW_LENGTH 200
void printerr(char* msg) {
printf("\n%s\n", msg);
fflush(stdout);
#if defined (__WIN32__)
system("PAUSE");
@kopiro
kopiro / base-convertor.c
Created June 14, 2011 22:22
Convert any number from base X to base X
char* base_converter(char* nbasefrom, int basefrom, int baseto) {
const char* SYMBOLS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if (basefrom<=0 || basefrom>strlen(SYMBOLS) || baseto<=0 || baseto>strlen(SYMBOLS)) {
fprintf(stderr, "Base unallowed");
return NULL;
}
int i, nbaseten=0;
if (basefrom!=10) {
int sizenbasefrom = strlen(nbasefrom);
for (i=0; i<sizenbasefrom; i++) {
@kopiro
kopiro / base-converter.js
Created June 15, 2011 17:52
Convert any number from base X to base X in Javascript
function base_converter(nbasefrom, basefrom, baseto) {
var SYMBOLS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if (basefrom<=0 || basefrom>SYMBOLS.length || baseto<=0 || baseto>SYMBOLS.length) {
console.log("Base unallowed");
return null;
}
var i, nbaseten=0;
if (basefrom!=10) {
var sizenbasefrom = nbasefrom.length;
for (i=0; i<sizenbasefrom; i++) {
@kopiro
kopiro / webchange.bash
Created June 15, 2011 18:18
Check a webpage everytime in Bash
#!/bin/bash
me=$(basename $0)
os=$(uname)
function usage
{
echo
echo "Usage"
echo
@kopiro
kopiro / jft-down-profile-v2.js
Created June 16, 2011 11:06
Scroll down a Facebook profile (v2)
javascript:
var TIMER = 3000;
var foo_id = null;
function ssscript() {
if (foo_id) stopscript();
else startscript();
}
@kopiro
kopiro / click-prototype.js
Created June 23, 2011 19:22
Simulate click in any DOM element
HTMLAnchorElement.prototype.click = function (){
var e = document.createEvent("HTMLEvents");
e.initEvent("click",true,true);
return !this.dispatchEvent(e);
}
@kopiro
kopiro / feed-reader.js
Created June 27, 2011 22:23
Read RSS with Google Api
jQuery.ajax({
url: "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q=" + encodeURIComponent(feedurl),
dataType: "json",
success: function (data) {
content = data.responseData.feed;
}
});
@kopiro
kopiro / async-for.js
Created July 7, 2011 09:48
Async FOR in Javascript
afor = function(a, b, c, t, f) {
eval(a);
if (eval(b)) {
f.apply();
eval(c);
setTimeout(function(){ afor(null,b,c,t,f) }, t);
}
}