Skip to content

Instantly share code, notes, and snippets.

@lopespm
lopespm / build_ico.sh
Created October 6, 2018 00:20
Pack a multi-dimension .ICO from a source image, using imagemagick
#!/bin/bash
build_folder="build"
source_image="source-image.png"
mkdir $build_folder
convert $source_image -scale 16 $build_folder/16.png
convert $source_image -scale 32 $build_folder/32.png
convert $source_image -scale 48 $build_folder/48.png
@lopespm
lopespm / index.js
Last active October 26, 2018 23:46 — forked from Jimbly/index.js
Steam CD Key Batch query
const assert = require('assert');
const async = require('async');
const fs = require('fs');
let request = require('request');
const FileCookieStore = require('tough-cookie-filestore');
if (!fs.existsSync('cookies.json')) { fs.writeFileSync('cookies.json', '{}');}
let j = request.jar(new FileCookieStore('cookies.json'));
request = request.defaults({ jar : j });
@lopespm
lopespm / camera_icon_unity.svg
Created December 14, 2018 23:17
SVG camera icon, same as the symbol seen in the Unity Editor
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lopespm
lopespm / OSX-Convert-MOV-GIF.md
Created December 25, 2018 12:05 — forked from tskaggs/OSX-Convert-MOV-GIF.md
Creating GIFs from .MOV files in OSX using FFmpeg and ImageMagick

Convert MOV to GIF using FFmpeg and ImageMagick

I tried a few different techniques to make a GIF via command-line and the following gives me the best control of quality and size. Once you're all setup, you'll be pumping out GIFs in no time!

Preparation

Install FFmpeg

  • $ brew install ffmpeg [all your options]
    • Example: $ brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-frei0r --with-libass --with-libvo-aacenc --with-libvorbis --with-libvpx --with-opencore-amr --with-openjpeg --with-opus --with-rtmpdump --with-schroedinger --with-speex --with-theora --with-tools

Install ImageMagick

@lopespm
lopespm / find_largest_binary_tree_complete.py
Last active February 18, 2019 12:58
Returns the size of the largest binary subtree that is complete, in Python - variant for exercise 9.1 on EPI (Elements of Programming Interviews)
# Returns the size of the largest binary subtree that is complete, in Python - variant for exercise 9.1 on EPI (Elements of Programming Interviews)
# The gist of the solution is to keep track of the subtree's current number of nodes, current height and maximum height until that point.
# With the current number of nodes and height, one can calculate the root's own number of nodes and height via its direct childs respective information,
# taking into to consideration the relation between the child heights and if they are perfect subtrees or not.
# Solution is O(n) time complexity and O(h) space complexity (function call stack corresponds from the root through the unique path to the current node)
from collections import namedtuple
class BTN():
@lopespm
lopespm / dutch_flag_four_colors.py
Last active March 28, 2019 21:43
Dutch national flag problem: four colors - in Python
# (Variant for exercise 5.1 on EPI (Elements of Programming Interviews))
# The rationale behind it is to squeeze the forth color (middle right color) in between the middle left and right sub-arrays. It defines the colors as the algorithm progresses.
# It has a O(n) time complexity and O(1) space complexity
from typing import List
def dutch_variant_four_colors(array: List[int]) -> List[int]:
left = array[0]
mid_left = None
right = None
@lopespm
lopespm / is_prefix_in_strings.py
Created April 1, 2019 15:59
Test if prefix is present in an array of sorted strings problem (Python)
# (Variant #4 for exercise 11.1 on EPI (Elements of Programming Interviews))
# The rationale behind it to perform a binary search which only considers a given character index of the strings.
# If these are present, continue to the next character index. If any of the prefix characters cannot be found in any string, return immediatly
# Considering n strings and k prefix length:
# Time complexity: O(k * log(n))
# Space complexity: O(1)
from typing import List
def first(items: List[str], prefix: str, i: int, c: str, left: int, right: int):

Keybase proof

I hereby claim:

  • I am lopespm on github.
  • I am lopespm (https://keybase.io/lopespm) on keybase.
  • I have a public key ASBVOGTQ7FFo3e2z4-HGjCwpsxKjqroop4en_wFUDWevBwo

To claim this, I am signing this object:

@lopespm
lopespm / print_levels_tree.py
Created April 6, 2019 12:24
Prints a given tree in levels, using BFS - using Python
# Print tree by levels - using BFS
# The idea behind it is to use BFS and keep a level marker integer which marks the end the last node of the level. This is similar to Naresh's sentinel approach, but without the need of inserting a sentinel inside the queue, since this is accomplished by the level marker.
# Time complexity of O(n)
# Space complexity: O(2^tree_height)
from collections import deque
class Node:
def __init__(self, data, left=None, right=None):
self.data = data
@lopespm
lopespm / is_valid_sudoku.py
Last active May 6, 2019 17:40
The Sudoku Check Problem - Alternative Solution (Python)
# Alternative python solution for 5.17 The Sudoku Check Problem on EPI (Elements of Programming Interviews)) (September 2018 edition)
# For an nxn Sudoku grid:
# Time complexity: O(n^2)
# Space complexity: O(n)
from typing import List
import math
from typing import List, Set
import math