Skip to content

Instantly share code, notes, and snippets.

View mllopart's full-sized avatar

Marc Llopart mllopart

View GitHub Profile
@mllopart
mllopart / Dragonball.php
Created June 14, 2017 17:04
Example of an easy class in PHP
<?php
class Dragonball {
public $ballCount = 0;
public function iFoundaBall() {
if ($this->ballCount < 7) {
$this->ballCount++;
} else {
echo("You can ask your wish!");
$this->ballCount = 0;
@mllopart
mllopart / sum_integers_from_coma_string.php
Last active June 14, 2017 16:37
From the variable input sum the integer values of it
<?php
$input = "1,2,3,4,5,6,7";
$sum = 0;
print($input);
$input_arr = explode(",", $input);
foreach($input_arr as &$inp)
{
@mllopart
mllopart / randomArray.js
Created June 13, 2017 18:36
Random numbers in an array
/*Function to return an array containing *length* random numbers
and having the range from 0 to *max* */
function randomArray(length, max) {
return Array.apply(null, Array(length)).map(function() {
return Math.round(Math.random() * max);
});
}
/* function than shuffle an array */
function shuffle(array) {
@mllopart
mllopart / discover_kill_sessions.sql
Last active May 23, 2017 16:09
Oracle - Query to detect active sessions, in order to kill them :)
/*Query to detect active sessions, in order to kill them in Oracle */
SELECT s.inst_id,
s.sid,
s.serial#,
p.spid,
s.username,
s.osuser,
s.machine,
s.program,
'ALTER SYSTEM KILL SESSION '''||s.sid||','||s.serial#||''' IMMEDIATE;' as cmd
@mllopart
mllopart / TowerHanoi.lisp
Last active April 4, 2017 14:22
Tower of Hanoi problem in LISP
(defun Hanoi (n origin destination auxiliar)
(if (= n 1) (moure 1 origin destination)
(progn (Hanoi (- n 1) origin auxiliar destination)
(moure n origin destination)
(Hanoi (- n 1) auxiliar destination origin))))
(defun moure (k origin destination)
(print (list 'move 'disk k
'from 'column origin
'to 'column destination)))