Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / userChrome.css
Last active September 19, 2018 00:40
Custom Firefox userChrome.css for dark private tabs when using light theme
/* How to Create a userChrome.css File: https://www.userchrome.org/how-create-userchrome-css.html */
/* Dark background color for private browsing tabs, with corresponding lighter text color */
#main-window[privatebrowsingmode="temporary"] #tabbrowser-tabs {
/*--tab-line-color: #8000d7 !important;*/
background-color: #000000 !important;
color: #ffffff !important;
}
@lopespm
lopespm / gist:9dd2639be43ec61e8f452f9cbae131cd
Created February 14, 2018 22:45
Use openSSL to verify a server's certificate
# In OSX, export all your root certicates through Keychain to "Certificates.pem" (for example)
openssl s_client -CAfile Certificates.pem -connect learnbreak.com:443 -servername learnbreak.com | openssl x509 -noout -subject -issuer
@lopespm
lopespm / useful_android_adb_commands.txt
Created December 1, 2017 17:45
Useful android ADB commands
# Show Tasks
adb shell dumpsys activity activities | sed -En -e '/Stack #/p' -e '/Running activities/,/Run #0/p'
@lopespm
lopespm / EnumerableMidRange.cs
Last active May 30, 2017 21:32
MidRange Enumerable Extension (C# LINQ)
using System.Collections.Generic;
using System.Linq;
static class EnumerableExtensions
{
/// <summary>
/// Calculate the enumerable's mid-range https://en.wikipedia.org/wiki/Mid-range
/// </summary>
public static float MidRange(this IEnumerable<float> source)
{