Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / .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 / 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 / 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
const STATUSNET_STATUS_MAX_LEN = 140;
const STATUSNET_DOMAIN = "mozilla.status.net";
const STATUSNET_NAME = "mozilla status"; /* Change the name of command manually */
var noun_type_statusnet_user = {
label: "user",
rankLast: true,
noExternalCalls: true,
cacheTime: 0,
suggest: function nt_twuser_suggest(text, html, cb, selected) {
/* This command open the profile folder */
function openLocalFolder(dir){
nsLocalFile = Components.Constructor("@mozilla.org/file/local;1","nsILocalFile", "initWithPath");
new nsLocalFile(dir).reveal();
}
CmdUtils.CreateCommand({
names: ["open-profile"],
description: "Open the profile directory in your file explorer..",
help: "Type open-profile to open the profile folder.",
author: {
/* This command open the profile folder */
function openLocalFolder(dir){
nsLocalFile = Components.Constructor("@mozilla.org/file/local;1","nsILocalFile", "initWithPath");
new nsLocalFile(dir).reveal();
}
CmdUtils.CreateCommand({
names: ["open-profile"],
description: "Open the profile directory in your file explorer..",
help: "Type open-profile to open the profile folder.",
author: {
/* This is a template command. */
CmdUtils.CreateCommand({
names: ["example"],
description: "A short description of your command.",
help: "How to use your command.",
author: {
name: "Your Name",
email: "[email protected]",
homepage: "http://labs.mozilla.com/",
},