Skip to content

Instantly share code, notes, and snippets.

@lucnap
lucnap / gist:d7f8d8699c82d50714da2d0cd6c8c9ff
Created May 9, 2016 10:55
WINDOWS XP PROFESSIONAL SP2 PRODUCT KEY
Professional SP2 VOL CCMWP-99T99-KCY96-FGKBW-F9WJT
@lucnap
lucnap / fb-page-access-token-no-expire
Last active October 22, 2021 09:53
How to get a Facebook Page Access Token that doesn't expire Never!
How to get a Facebook Page Access Token that doesn't expire Never!
- Go to http://developers.facebook.com/tools/explorer/
- Get a User Access Token with a permission "manage_pages"
- Convert this short-lived access token into a long-lived one by making this Graph API call:
https://graph.facebook.com/v2.6/oauth/access_token?client_id=<your FB App ID >&client_secret=<your FB App secret>&grant_type=fb_exchange_token&fb_exchange_token=<your short-lived access token>
- Make a call Graph API:
https://graph.facebook.com/v2.6/<your personal account FB user id>/accounts?access_token=<your long-lived access token>
- The returned access_token has no expiration unless you change your password or not more admin of the target page or deauthorize FB page
@lucnap
lucnap / gist:4c63c94480a58806c98d0f623802200c
Created September 27, 2020 07:48
Python: map field names to indices in database cursor
def generatefieldmap(cursor):
""" Given a DB API 2.0 cursor object that has been executed, returns
a dictionary that maps each field name to a column index; 0 and up. """
results = {}
column = 0
for d in cursor.description:
results[d[0]] = column
column = column + 1
@lucnap
lucnap / gist:fc3b67f6120fc26f8696064fec94de03
Last active September 26, 2020 08:34
Compile python programs to Widows executable
Install PyInstaller
if using Virtual Env (very likely) compile spcifying the folder of the modules
Example:
pyinstaller main.py --paths venv\Lib\site-packages --onefile
otherwise you will get an error of module not found when moving the executable to another machine
This is very useful when using libraries like MySQLdb for example
@lucnap
lucnap / gist:a4c755b779e6c40b70115a593c4c2167
Created August 25, 2020 16:13
Node.Js search and replace in files in directory recursively
const fs = require('fs');
const path = require('path');
const walkSync = (dir, filelist = []) => {
fs.readdirSync(dir).forEach(file => {
filelist = fs.statSync(path.join(dir, file)).isDirectory()
? walkSync(path.join(dir, file), filelist)
: filelist.concat(path.join(dir, file));
@lucnap
lucnap / lunaenergianaz.php
Created April 24, 2020 14:27
Blocks outgoing order confirmation email
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
class LunaEnergiaNaz extends Module {
@lucnap
lucnap / gist:c250be1333475736ddd77ad2dea854ef
Last active April 23, 2020 07:31
Cloudflare htaccess restrict IP
SetEnvIF CF-Connecting-IP "10.20.30.40" MySecretIP
<Files index.php>
order allow,deny
allow from env=MySecretIP
</Files>
@lucnap
lucnap / gist:d4f8884b51d48d7af651bf3485fd2302
Last active June 25, 2019 17:25
Resizing and Padding image to keep a constant aspect ratio with ImageMagick
Resizing and Padding image to keep a constant aspect ratio with ImageMagick
This command center any given image in an area of 768x1024 and resize to fit the aspect ratio 768x1024
magick mogrify -resize 768x1024 -background "#fff" -gravity center -extent 768x1024 *Copia.jpg
Example Batch file, ResizeAndPadImage.bat
@lucnap
lucnap / note su mysql
Created June 5, 2019 18:25
mysql secure passwords on command line
# impostare la password in modo sicuro con il seguente
mysql_config_editor set --login-path=mypath1 --host=localhost --user=username --password
# questo al fine di poter utilizzare mysqldump in modo sicuro con
mysqldump --login-path=mypath1 nomeDelDataBase > /path/dove/metto/i/backup/nomeDelDatabase.sql
@lucnap
lucnap / PrefixFromCountryISO
Created June 3, 2019 11:31
Seleziona il giusto prefisso in base al codice ISO
strNazione = Doc.CustomField(584)
prefisso = ""
Select Case strNazione
Case "HU", "HUN"
prefisso = "36"
Case "UA", "UKR"
prefisso = "380"
Case "CH", "CHE"
prefisso = "41"