Skip to content

Instantly share code, notes, and snippets.

View thejsj's full-sized avatar

Jorge Silva thejsj

View GitHub Profile
def all_perms(elements):
if len(elements) <=1:
yield elements
else:
for perm in all_perms(elements[1:]):
for i in range(len(elements)):
#nb elements[0:1] works in both string and list contexts
yield perm[:i] + elements[0:1] + perm[i:]
def determinePossiblities(i):
result = 1
for ii in range(i):
if(ii) == 0:
pass
elif(ii) == 1:
result = 1
else:
result = result * ii
if i > 0:
@thejsj
thejsj / calculatingGdpGrowth.py
Last active November 11, 2021 20:45
A little python script to calculate GDP Growth. There are multiple ways to do it; this is just one of them. By this standard, Spain had the 3rd highest GDP growth in the original eurozone (11 countries) from the first quarter 1999 to the last quarter of 2007.
import math
import operator
number_of_quarters_in_a_year = 4;
number_of_quarters = 9 * number_of_quarters_in_a_year;
countries = [
{ "name" : "Belgium", "starting_growth" : 58433.0, "end_growth" : 85113.0},
{ "name" : "Germany", "starting_growth" : 493890.0, "end_growth" : 614660.0},
{ "name" : "Ireland", "starting_growth" : 21348.8 ,"end_growth" : 48091.5},
@thejsj
thejsj / Nearest Even Integer To Square Root.py
Last active December 22, 2015 12:29
Given any random number (even in this case), find the two closest integers divisible by 2, or the two integers closes to the square root divisible by 2
import math
import random
def calc(num):
resultFound = False
for i in range(1,100):
ii = math.pow(2, i)
s = math.sqrt(num)
r = int(round(s / ii) * ii)
if r > 0:
@thejsj
thejsj / youtubePlayerClass.js
Last active May 21, 2023 01:03
A short script to integrate the Youtube Player API with Javascript.
var Video = function(id, index){
this.id = id;
this.index = index;
this.w = Math.random() * 200 + 100;
this.h = this.w * (9/16);
this.init();
this.volume = 50;
this.muted = false;
};
@thejsj
thejsj / createDatabaseAndUser
Created October 24, 2013 21:44
Bash script to automatically create MySQL databases where the database name and the username are the same. First argument: database name/username. Second argument: mysql_user password.
#!/bin/bash
params=" -uroot -p"
echo ' - - - - - - - '
echo 'DB Name : '$1
echo 'Password: '$2
# Create Database
echo ' - - - - - - - '
echo 'CREATE DATABASE IF NOT EXISTS $1;'
# Grant Options (Creates User Automatically)
echo ' - - - - - - - '
@thejsj
thejsj / createDatabaseAndUser
Last active January 1, 2016 05:29
Another iteration into a script that creates a database and user
#!/bin/bash
params=" -uroot -p"
echo ' - - - - - - - '
echo 'DB Name : '$1
echo 'Password: '$2
# Create Database
echo ' - - - - - - - '
echo 'CREATE DATABASE IF NOT EXISTS $1;'
# Grant Options (Creates User Automatically)
echo ' - - - - - - - '
@thejsj
thejsj / animationClass.js
Created December 25, 2013 04:06
A very nice, useful animation class. Originally written in Processing. I translated it to JS.
var SoftFloat = (function(){
console.log('Hello World');
function SoftFloat() {
this.value = this.source = this.target = 0;
this.targeting = false;
this.enabled = true;
this.ATTRACTION = 0.0000000001;
this.DAMPING = 0.000005;
@thejsj
thejsj / createRepo.sh
Created December 25, 2013 20:39
Shell script to create github repo remotely using the github API
#!/bin/sh
REPO_NAME=$1
echo "NEW REPO NAME: $REPO_NAME"
echo -n "Are you sure you want to create github repo with name '$REPO_NAME' ? (y/n) > "
if read -t 5 response; then
if [ 'y' = "$response" ]; then
echo "Ok. Let's continue creating Repo"
echo "Creating Repository: $REPO_NAME"
curl -u 'thejsj' https://api.github.com/user/repos -d "{\"name\":\"$REPO_NAME\"}"
# Remember replace USER with your username and REPO with your repository/application name!
@thejsj
thejsj / createWordpress.sh
Last active January 1, 2016 09:39
Create a Wordpress installation through the command line with its corresponding MySQL database.
#!/bin/bash
# Creating Wordpress Instalation
THIS_YEAR=$(date +%Y)
if [[ -z "$1" ]]; then
PROJECT_NAME=$1
fi;
if [[ -z "$PROJECT_NAME" ]]; then
read -p "Wordpress Project Name : " PROJECT_NAME