Skip to content

Instantly share code, notes, and snippets.

@kopiro
kopiro / autosshsync.sh
Created August 14, 2011 14:55
AutoSync Directory with SSH Server
#!/bin/bash
# Sync directory between client and SSH server
usr='VOSTRO_UTENTE_SUL_SERVER_SHH'
srv='SSH_SERVER'
rdir='~/remote/directory/to/sync'
ldir='~/local/directory/to/sync/' #use the / at the end to do not sync the same folder, but only files in the directory
slp='30' # timeout between each request, in seconds
while (true) do
@kopiro
kopiro / forward-all-fb-msg.js
Created August 16, 2011 13:31
Forward all Facebook message
MessagingManager.getState().enterForwardMode();
var allMsg = $$(".MessagingMessage");
var evtClk = document.createEvent("HTMLEvents");
evtClk.initEvent("click", true, true);
for (var i=0; i<allMsg.length; i++)
allMsg[i].dispatchEvent(evtClk);
$$("#ForwardMessages input")[0].click();
@kopiro
kopiro / use-joomla-classes-public.php
Created August 26, 2011 13:15
Use Joomla Classes in external PHP script
<?php
define( '_JEXEC', 1 );
define( '_VALID_MOS', 1 );
define( 'JPATH_BASE', realpath('.'));
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
?>
@kopiro
kopiro / set-cookie-good.php
Created August 26, 2011 13:38
Set cookie for all pages PHP
@kopiro
kopiro / gist-coda-syntax.css
Created August 27, 2011 18:13
Get the Coda i-syntax-coloring in GIST snippets
.gist {
color: #fff !important;
background: #fff !important;
padding: 3px !important;
border: 1px solid #888 !important;
overflow: auto !important;
}
.gist .gist-file {
border: none !important;
margin-bottom: 0 !important;
@kopiro
kopiro / amicable.c
Created September 8, 2011 07:42
Find amicable numbers in C
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
long sumod(long x) {
long i, s = 1;
for (i=2; i<=(x/2); i++)
if ((int)x%i==0)
s += i;
return s;
@kopiro
kopiro / set-cropped-image.js
Created September 15, 2011 11:23
Set thumb-image in Javascript
setThumbImage = function(e, src) {
var img = new Image();
img.src = src;
img.onload = function() {
console.log("img loaded");
e.style.backgroundImage = 'url('+src+')';
e.style.backgroundPosition = 'center';
e.style.backgroundRepeat = 'no-repeat';
e.style.backgroundSize = (img.width>img.height ? 'auto 100%' : '100% auto');
}
@kopiro
kopiro / find-best-facebook-friends.js
Created October 2, 2011 12:03
Find your "best friends" on Facebook
javascript:
var friends = {};
var bfriends = [];
var char = 97;
if (!q) var q = document.querySelector("#q");
q.style.color="white";
go = function(){
q.blur();
var charS = String.fromCharCode(char);
char++;
@kopiro
kopiro / wikipedia-obscured.php
Created October 6, 2011 12:39
Access to Wikipedia Obscured (4-Oct)
<?php
$q = $_GET["q"];
if (!$q) $q = $_GET["search"];
$q = str_replace(" ", "_", ucwords($q));
if (!$q) {
header("location: index.php?q=Wikipedia");
die();
}
if (file_exists("./cache/$q.html")) {
echo file_get_contents("./cache/$q.html");
@kopiro
kopiro / check-fbchat.js
Created October 8, 2011 06:41
Check names to Facebook Chat
javascript:
ytAlert = function()
{
console.log("Alert!");
window.open("http://www.youtube.com/watch?v=xRrfg_uAzwg&feature=grec_index");
}
onlineString = function(b)
{