Skip to content

Instantly share code, notes, and snippets.

Avatar

Rogério Chaves rogeriochaves

View GitHub Profile
@rogeriochaves
rogeriochaves / parser.rb
Created Apr 13, 2021
Parse ruby .inspect string to be eval'd
View parser.rb
def deinspect(str, level=0)
str.gsub!(/:0x0[^ ]+/, '')
matches = str.match(/<([\w:]+) (.*)>/)
return str unless matches
head = matches[1]
body = matches[2]
hash_content = nil
@rogeriochaves
rogeriochaves / links.md
Last active Mar 24, 2021
Pt-BR Data Science Links Scrapping
View links.md
@rogeriochaves
rogeriochaves / ffmpeg_scripts.sh
Last active Mar 1, 2021
ffmpeg useful scripts
View ffmpeg_scripts.sh
# Convert video to gif
ffmpeg -i input.mp4 -filter_complex "[0]fps=10" output.gif
ffmpeg -i input.mov -r 10 -f image2pipe -vcodec ppm - | convert -loop 0 -layers Optimize - output.gif
# Convert mkv to mp4
ffmpeg -i input.mkv -codec copy output.mp4
View index.js
const thiagoWay = (lista) => {
let ar = lista.map((el) => el.name);
let array_elements = ar.sort();
let current = null;
let cnt = 0;
for (var i = 0; i < array_elements.length; i++) {
delete lista[i].id;
if (array_elements[i] != current) {
@rogeriochaves
rogeriochaves / fetchingState.js
Last active Dec 15, 2020
Javascript Fetching State without Booleans
View fetchingState.js
const NOT_ASKED = 'NOT_ASKED';
const LOADING = 'LOADING';
const SUCCESS = 'SUCCESS';
const ERROR = 'ERROR';
export const notAsked = () => ({ state: NOT_ASKED });
export const loading = () => ({ state: LOADING });
export const success = result => ({ state: SUCCESS, result });
export const error = message => ({ state: ERROR, message });
View style.css
.ghx-controls-filters, .ghx-qty, .ghx-issue-fields .ghx-key, .ghx-card-footer .ghx-type, .ghx-card-footer .ghx-flags, .ghx-card-footer .ghx-end, .ghx-card-footer .ghx-days, #announcement-banner {
display: none!important;
}
#ghx-pool-column {
padding: 0 20px;
}
.ghx-issue .ghx-highlighted-fields .ghx-highlighted-field {
max-width: none;
View code.js
function trackClick(name) {
if (!name) throw "track needs a name";
ga.track(name);
}
View server.py
questions_so_far = []
answers_so_far = []
@app.route('/')
def index():
global questions_so_far, answers_so_far
question = request.args.get('question')
answer = request.args.get('answer')
View server.py
questions = {
1: 'Is your character yellow?',
2: 'Is your character bald?',
3: 'Is your character a man?',
4: 'Is your character short?',
}
characters = [
{'name': 'Homer Simpson', 'answers': {1: 1, 2: 1, 3: 1, 4: 0}},
{'name': 'SpongeBob SquarePants', 'answers': {1: 1, 2: 1, 3: 1, 4: 0.75}},
View server.py
def calculate_character_probability(character, questions_so_far, answers_so_far):
# Prior
P_character = 1 / len(characters)
# Likelihood
P_answers_given_character = 1
P_answers_given_not_character = 1
for question, answer in zip(questions_so_far, answers_so_far):
P_answers_given_character *= max(
1 - abs(answer - character_answer(character, question)), 0.01)