Skip to content

Instantly share code, notes, and snippets.

View mvsusp's full-sized avatar

Marcio Vinicius dos Santos mvsusp

View GitHub Profile
#!/usr/bin/env ruby
system "mkdir dump" unless File.directory? "dump"
%w(rubygems csv nokogiri open-uri active_support ruby-debug pdfkit).each do |req|
require req
end
def generate_page_uri(page)
return nil if page.empty?
base_url = "http://gatherer.wizards.com/Pages/Search/Default.aspx?"
//Returns the number of elements between the two words, or null if at least one of the words hasn't an occurrence in the array
public Integer shortestPath(String firstWord, String secondWord, String pathToWordFile){
//Just checking if the two words are the same
if( firstWord.equals(secondWord) ){
return 0;
}
String[] words = new Scanner(pathToWordFile).nextLine().split(" ");
@mvsusp
mvsusp / floorBST.java
Created September 3, 2012 23:49
floor bst
public Node floor(Node x, Key key){
if( x == null) return null;
Integer cmp = key.compareTo(x.key);
if(cmp < 0) return floor(x.left, key);
else if(cmp == 0) return x;
Node t = floor(x.right, key);
if(t != null ) return t;
@mvsusp
mvsusp / long_life_to_the_king.md
Last active August 29, 2015 14:04
The king is dead, long life to the king ! or **Short lived attributes on long lived objects**

One challeging problem amuzed me today: the best way to work with short lived attributes on long lived objects. Like the iron throne, sometimes the attribute, in this case the Westeros King changes constantly and you don't want to check always the value, in this case the current king:

public class IronThrone{
  private KingChecker _kingChecker;

  public IronThrone(KingChecker kingChecker){
    _kingChecker = kingChecker;
  }
 
@mvsusp
mvsusp / crawler.js
Created May 17, 2015 13:01
motor js
var express = require('express');
var router = express.Router();
router.get('/crawler', function(req, res, next) {
var elements,
data,
util = require('util'),
spawn = require('child_process').spawn,
ls = spawn('phantomjs', ['motor.js', 'http://www.medium.com']);
@mvsusp
mvsusp / AlignWithGround.cs
Last active May 29, 2016 13:37
unity tips and tricks
using UnityEngine;
using UnityEditor;
public class AlignWithGround : MonoBehaviour {
// Use this for initialization
void Start () {
}
@mvsusp
mvsusp / keras_to_tf_serving.py
Created February 16, 2018 01:50
keras model to tf serving model example
import tensorflow as tf
from tensorflow.contrib.learn.python.learn.utils import saved_model_export_utils
from tensorflow.python.estimator.export.export import build_raw_serving_input_receiver_fn
from tensorflow.python.keras._impl.keras.engine.topology import InputLayer
from tensorflow.python.keras._impl.keras.layers import Conv2D, Activation, MaxPooling2D, Dropout
from tensorflow.python.keras._impl.keras.models import Sequential
from tensorflow.python.keras._impl.keras.optimizers import rmsprop
from tensorflow.python.saved_model.signature_constants import PREDICT_INPUTS
HEIGHT = 32
@mvsusp
mvsusp / print_tensors_in_checkpoint_file.py
Created February 16, 2018 19:43
print_tensors_in_checkpoint_file
from tensorflow.python import pywrap_tensorflow
def print_tensors_in_checkpoint_file(file_name, tensor_name, all_tensors,
all_tensor_names):
"""Prints tensors in a checkpoint file.
If no `tensor_name` is provided, prints the tensor names and shapes
in the checkpoint file.
If `tensor_name` is provided, prints the content of the tensor.
Args:
@mvsusp
mvsusp / keras_embeddings.py
Created February 28, 2018 04:19
keras_embeddings
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import print_function
import sys
import numpy as np
import os
import tensorflow as tf
@mvsusp
mvsusp / tf_keras_early_stopping.py
Last active February 28, 2018 08:36
TF Keras Early stopping
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import json
import pickle
import tensorflow as tf
from google.protobuf import json_format
from tensorflow.core.framework import tensor_pb2