Skip to content

Instantly share code, notes, and snippets.

View riccamastellone's full-sized avatar

Riccardo Mastellone riccamastellone

View GitHub Profile
@riccamastellone
riccamastellone / nsCountryCpdes.php
Last active January 7, 2021 06:53 — forked from groggu/nsCountryCpdes.php
Convert standard ISO country codes to NetSuite's constants
/***
* Convert standard ISO country codes to NetSuite's world
*
* @param $isoCode
*
* @return string|bool
*/
public function convertCountryCode($isoCode)
{
@riccamastellone
riccamastellone / maximise_profit.py
Created June 29, 2017 10:27
We want to maximise profit selling metal rods: we can cut them to sell more, but performing cuts, has a cost
# We want to maximise profit selling metal rods: we can cut them to sell more, but performing cuts, has a cost
#
# If we sell metal rods of length, he receives N x L x metal_price.
# The remaining smaller metal rods will be thrown away.
# To cut the metal rods, we needs to pay cost_per_cut for every cut.
def get_max_profit(cost_per_cut, price, rods):
longest_rod = max(rods)
max_profit = 0
@riccamastellone
riccamastellone / adjacency_matrix_clusters.py
Last active June 29, 2017 10:36
Count the isolated sub-graphs starting from the adjacency matrix
def generate_graph(z):
"""
Generates a dictionary {vertex: set(links)} from the matrix
"""
graph = {}
for key, value in enumerate(range(0, len(z))):
z[value] = list(z[value])
graph[value] = set()
for k, v in enumerate(z[value]):
if int(z[value][k]) == 1:
@riccamastellone
riccamastellone / XGBoost_EA.ipynb
Last active November 23, 2017 15:54
XGBoost parameter search with evolutionary algorithm
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@riccamastellone
riccamastellone / jquery.autolink.js
Last active December 28, 2015 08:18
Two simple jQuery plugins to detect links (autolink) and email (automail) and make them clickable
@riccamastellone
riccamastellone / db-backup.sh
Created July 25, 2013 09:51
Extremely simple script to list and backup all your MySQL dbs to Amazon S3 using s3cmd (http://s3tools.org/).
#!/bin/bash
dblist=`mysql -u root -pYOURPASSWORD -e "show databases" | sed -n '2,$ p'`
for db in $dblist; do
if [ $db != 'performance_schema' ] && [ $db != 'mysql' ] && [ $db != 'information_schema' ]
then
mysqldump -u root -pYOURPASSWORD $db > /var/backup/db/$db.sql
s3cmd --no-progress --mime-type="application/octet-stream" put /var/backup/db/$db.sql s3://YOURBUCKET/backup-db/$db.sql
fi
done