Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@lucasrizoli
lucasrizoli / fizzbuzz.py
Created January 1, 2023 01:35
One-line FizzBuzz in Python 3
# One-line FizzBuzz in Python 3 (for my son, who asked me to show him it was possible)
print("\n".join(["Fizz"*(n%3 == 0) + "Buzz"*(n%5 == 0) or str(n) for n in range(1, 15+1)]))
@lucasrizoli
lucasrizoli / enums3.rs
Created July 15, 2021 18:45
solution to rustlings enums3.rs
// enums3.rs
// Address all the TODOs to make the tests pass!
enum Message {
Move(Point),
Echo(String),
ChangeColor((u8,u8,u8)),
Quit,
}
# Convert input.avi to out.mp4
ffmpeg -i input.avi -c:v libx264 -crf 19 -preset slow -c:a aac -b:a 192k -ac 2 out.mp4
# Clip using ffmpeg
## no reencode
ffmpeg -i in.mp4 -ss [start] -t [duration] -c copy out.mp4
ffmpeg -i in.mp4 -ss [start] -to [end] -c copy out.mp4
## yes reencode
ffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4
@lucasrizoli
lucasrizoli / gist:e055bf2c18218ffdcee7
Created February 23, 2015 18:15
PowerPoint Macro to switch language of document to en-CA
Option Explicit
Public Sub ChangeSpellCheckingLanguage()
Dim j As Integer, k As Integer, scount As Integer, fcount As Integer
scount = ActivePresentation.Slides.Count
For j = 1 To scount
fcount = ActivePresentation.Slides(j).Shapes.Count
For k = 1 To fcount
If ActivePresentation.Slides(j).Shapes(k).HasTextFrame Then
' List of available LanguageID values at https://msdn.microsoft.com/en-us/library/aa432635.aspx
ActivePresentation.Slides(j).Shapes(k) _
@lucasrizoli
lucasrizoli / gist:7013194
Last active December 25, 2015 17:29
regex punctuation class
import re
punctexp = re.compile(r"[\!\"\#\$\%\&\\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^_\`\{\|\}\~]")
# Could also…
# import string
# re.compile('[{0}]'.format(re.escape(string.punctuation)))
@lucasrizoli
lucasrizoli / gist:5577646
Created May 14, 2013 17:06
Factorial functions, one recursive and one iterative Wanted to see if there were any significant differences in performance. http://jsperf.com/factorial-recursive-v-iterative
var factorialRecursive = (function () {
// 0! = 1 just 'cause
var factorials = [ 1 ];
return function fFactorial( n ) {
if ( n < 0 ) {
// negative n! not defined
return null;
} else if ( factorials[ n ] ) {
return factorials[ n ];
var dict = {
"Videogames" : "Things",
"Videogame" : "Thing",
"videogames" : "things",
"videogame" : "thing",
"Games" : "Things",
"Game" : "Thing",
"games" : "things",
"Games" : "Things",
"game" : "thing",
@lucasrizoli
lucasrizoli / gist:4178397
Last active July 9, 2018 13:32
OS X/PlayStation/Xbox symbols & entity codes
Symbol HTML entity Alt entity Alt entity Name
&#8592; &#x2190; &larr; Left Arrow
&#8593; &#x2191; &uarr; Up Arrow
&#8594; &#x2192; &rarr; Right Arrow
&#8595; &#x2193; &darr; Down Arrow
&#8677; &#x21E5; Tab
&#8676; &#x21E4; Back Tab
&#8679; &#x21E7; Shift
Caps Lock
@lucasrizoli
lucasrizoli / gist:4079640
Created November 15, 2012 16:42
Solution to FizzBuzz problem
/**
* Inspired by http://www.globalnerdy.com/2012/11/15/fizzbuzz-still-works/
*
* Write a program that prints the numbers from 1 to 100, but
* for multiples of 3 print "Fizz" instead of the number and
* for the multiples of 5 print "Buzz." For numbers which are
* multiples of both 3 and 5 print "FizzBuzz."
*/
for( var i = 1; i <= 100; i += 1 ) {
@lucasrizoli
lucasrizoli / gist:2024505
Created March 12, 2012 20:30
Bookmarklet for converting UNIX/POSIX timestamp to date and time
javascript:(function(a){var b=parseInt(a.replace(/[\s|,]/g,""),10);alert(isNaN(b)?'"'+a+"\" doesn't look like a UNIX timestamp.":'"'+a+'" is\n'+new Date(b*(b>1e12?1:1e3)));})(window.getSelection().toString());