Skip to content

Instantly share code, notes, and snippets.

View lucax88x's full-sized avatar

Luca Trazzi lucax88x

View GitHub Profile
@ShirtlessKirk
ShirtlessKirk / luhn.js
Last active May 17, 2024 08:05
Luhn validation algorithm
/**
* Luhn algorithm in JavaScript: validate credit card number supplied as string of numbers
* @author ShirtlessKirk. Copyright (c) 2012.
* @license WTFPL (http://www.wtfpl.net/txt/copying)
*/
var luhnChk = (function (arr) {
return function (ccNum) {
var
len = ccNum.length,
bit = 1,
@carlok
carlok / istat.sql
Last active January 21, 2022 10:18
Script SQL per la memorizzazione dei Comuni, delle Province e delle Regioni d’Italia: usare la nuova versione su https://github.com/carlok/comuni_sql
---
--- Usare la nuova versione su https://github.com/carlok/comuni_sql
---
CREATE TABLE IF NOT EXISTS regioni (
id int(11) NOT NULL auto_increment,
nome varchar(100) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@jamlfy
jamlfy / balance.js
Last active December 26, 2015 13:29
To balance clustered nodejs actually generates greater stability
const cluster = require('cluster');
const http = require('http');
const httpProxy = require('http-proxy');
const _ = require('underscore');
var numCPUs = 10;
var isPort = 8080;
function estimatePi() {
var n = 10000000, inside = 0, i, x, y;
@hiddentao
hiddentao / gist:7300694
Last active January 22, 2019 05:04
An improvement on the angular.module() API, making it easier to split up modules into multiple files without having to worry about only registering them once.
/**
* Workaround to make defining and retrieving angular modules easier and more intuitive.
*/
(function(angular) {
var origMethod = angular.module;
var alreadyRegistered = {};
/**
@mobilemind
mobilemind / git-tag-delete-local-and-remote.sh
Last active June 11, 2024 11:25
how to delete a git tag locally and remote
# delete local tag '12345'
git tag -d 12345
# delete remote tag '12345' (eg, GitHub version too)
git push origin :refs/tags/12345
# alternative approach
git push --delete origin tagName
git tag -d tagName
@ramondelafuente
ramondelafuente / test_sudo_and_variables.yml
Last active March 17, 2023 23:38
Testing ansible "ansible_ssh_user" and "ansible_user_id" variables with sudo
- name: Testing variables with SUDO=NO
hosts: "*"
sudo: no
tasks:
- name: "PLAYBOOK SUDO=NO, TASK SUDO=NO"
command: whoami
register: whoami_output
sudo: no
- debug: var=whoami_output.stdout
@johnathan-sewell
johnathan-sewell / Jasmine it in forEach.js
Created May 8, 2014 08:42
Dry Jasmine "it" blocks in forEach
describe('validation', function() {
['startDate', 'endDate'].forEach(function(key) {
it('expects ' + key + ' to be in ISO format', function() {
model.set(key, '2014-04-29T15:04:53.078Z');
expect(model.isValid()).toEqual(true);
model.set(key, '2014/04/29');
expect(model.isValid()).toEqual(false);
});
});
});
@jmervine
jmervine / cert_convert.sh
Created November 17, 2014 21:57
openssl: convert cert from p7b to crt (or cer)
openssl pkcs7 -print_certs -in old.p7b -out new.crt
# openssl pkcs7 -print_certs -in old.p7b -out new.cer
@ca0v
ca0v / debounce.ts
Last active June 19, 2024 11:20
Typescript Debounce
// ts 3.6x
function debounce<T extends Function>(cb: T, wait = 20) {
let h = 0;
let callable = (...args: any) => {
clearTimeout(h);
h = setTimeout(() => cb(...args), wait);
};
return <T>(<any>callable);
}
kubectl get po --all-namespaces | grep Evicted | awk '{print $2, "--namespace", $1}' | xargs kubectl delete pod