Skip to content

Instantly share code, notes, and snippets.

@gialloporpora
gialloporpora / imgur.bat
Created June 12, 2012 21:53
Upload image on ImgUr (anonymous) with history using commandline. It requires sed and curl.
@echo off
REM Set you API KEY http://imgur.com/register/api_anon
set apikey=your_apikey_here
REM Usage:
REM img file_path [title] [caption]
REM img url [title] [caption]
REM title and caption are optional, quote them if they contains spaces or strange characters
REM Set the path where are located curl.exe and sed.exe
@gialloporpora
gialloporpora / apod.php
Last active October 6, 2015 06:07
With this code (PHP) you can create an URL that automatically redirect to the APOD (Astronomy Image Of the Day)
/*
With the following code you can create a static url that automatically redirect to the apod (Astronomy Image of the day
* You can use it like wallpaper in your Firefox's about:home page. Look at next file
Download Simple HTML parser from here:
http://simplehtmldom.sourceforge.net/
*/
<?php
function randomImage(){
$best_images = Array(
@gialloporpora
gialloporpora / .bashrc
Created June 20, 2012 21:16
Function to add an edit command to open files with Windows text editor in Cygwin
# Finally, thanking Larry Hall on cygwin newsgroup
# I have my edit command to use my favorite text editor on Cygwin :-D
# These lines must be inserted in .bashrc file in your home
function edit() {
cygstart /cygdrive/c/Programmi/Crimson\ Editor/cedt.exe "$(cygpath -w "$*")";
}
# Simpler, but useful, the open function
function open(){ cygstart "$*";}
@gialloporpora
gialloporpora / rsaexample.js
Created June 25, 2012 20:34
Some functions to understand RSA encryption with *little* numbers
findInverse=function(a,b){
n=b;x=0;lastx=1;
while (b!= 0){
q=~~(a/b);
temp=a;
a=b;
b=temp % b;
temp=x;
x= lastx - q*temp;
lastx=temp;
@gialloporpora
gialloporpora / magicbox.js
Created June 27, 2012 18:03
A joke to show in a funy way a binary encrypted string. It works better with strings of 7 characters
Number.prototype.toBinary=function(width, zero, one){
var b=this.toString(2);
var zeroString = '';
if (width) if ((width-b.length)>0) zeroString = Math.pow(10,width-b.length).toString().substr(1);
var output = zeroString + b;
if ((zero) && (one)) {
if (typeof(zero)=='number') zero=String.fromCharCode(zero);
if (typeof(one)=='number') one=String.fromCharCode(one);
output = output.replace(/0/g,zero);
output = output.replace(/1/g,one);
@gialloporpora
gialloporpora / computeSha256.js
Created July 12, 2012 11:11
Esempio per il gurppo it.comp.crittografia
/* SHA-256 implementation in JavaScript | (c) Chris Veness 2002-2010 | www.movable-type.co.uk */
/* - see http://csrc.nist.gov/groups/ST/toolkit/secure_hashing.html */
/* http://csrc.nist.gov/groups/ST/toolkit/examples.html */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
var Sha256 = {}; // Sha256 namespace
/**
* Generates SHA-256 hash of string
*
@gialloporpora
gialloporpora / base64.bat
Created July 13, 2012 16:00
Batch script to obtain the encoded base64 url of a file
@echo off
set tempfile="%~dp0\temp.txt"
set mimetypes=%~dp0mimetypes.txt
REM Extracting the extension of the file
set ext=%~x1_
REM Removing the period for using as correct variable name
set ext=%ext:~1,-1%
REM Load mimetypes from file, if some mimetype is missing update the file mimetypes.txt
REM for any mimetypes is created a variable mime_mimetype, for example mime_png for image/png
for /f "delims== tokens=1,2 eol=#" %%i in (%mimetypes%) do set mime_%%i=%%j
@gialloporpora
gialloporpora / tail.bat
Created July 31, 2012 17:23
Batch file to emulate tail command using SED
@echo off
if "%2"=="" (set lines=3) else (set lines=%2)
set /a lines=%lines% + 1
set sed="$q;N;%lines%,$D;ba"
sed -e :a -e %sed% %1
@gialloporpora
gialloporpora / lastfm.py
Created August 16, 2012 22:32
Download album art from Last.fm. It requires PyQuery module.
# download images from last.fm
# PyQuery is a very powerful module to parse HTML pages, but it is not by default distributed with Python
# if you want install it you need first install lxml module
# Same features of this script works only with pyquery, but the most important ones (download images of cover and artist) works without installing it
try:
from pyquery import PyQuery as pq
pyquery = True
except ImportError:
@gialloporpora
gialloporpora / example_base64.md
Created September 6, 2012 13:37
Esempio di pagina HTML codificata come URL

// Questa è una pagina web codificata in base64:

data:text/html;base64,PGh0bWw+DQo8aGVhZD4NCjx0aXRsZT4NClBoaXNoaW5nDQo8L3RpdGxlPg0KPC9oZWFkPg0KPGJvZHk+DQo8aDE+SGVsbG8gd29ybGQhPC9oMT4NCjxhIGhyZWY9ImRhdGE6dGV4dC9odG1sO2Jhc2U2NCxQR2gwYld3K0RRbzhhR1ZoWkQ0TkNqeDBhWFJzWlQ0TkNsQm9hWE5vYVc1bkRRbzhMM1JwZEd4bFBnMEtQQzlvWldGa1BnMEtQR0p2WkhrK0RRbzhhREUrU0dWc2JHOGdkMjl5YkdRaFBDOW9NVDROQ2p4aElHaHlaV1k5SW1acGJHVTZMeTh2UkRvdlEwbEJUMzR4TGtoVVRTSWdkR0Z5WjJWMFBTSmZZbXhoYm1zaVBreHBibXNnZEc4Z2RHaHBjeUJ3WVdkbFBDOWhQZzBLUEM5aWIyUjVQZzBLUEM5b2RHMXNQZz09IiB0YXJnZXQ9Il9ibGFuayI+TGluayB0byB0aGlzIHBhZ2U8L2E+DQo8L2JvZHk+DQo8L2h0bWw+