Skip to content

Instantly share code, notes, and snippets.

@totetmatt
totetmatt / ccc-2019.scala
Created December 18, 2019 15:36
Christmas Coding Challenge 2019 (Scala)
case class RegexOperator(c:Char,a:Option[Char]=None) {
def eqmatch(ch:Char): Boolean = ch == c || c == '.'
}
def parsePattern(p:String) =
p.foldLeft(Seq.empty[RegexOperator])( (agg,el)=> el match {
case '*' =>agg.init :+ agg.last.copy(a=Some('*'))
case c => agg :+ RegexOperator(c)
})
def regex(p:String,s:String): Boolean = {
@totetmatt
totetmatt / ccc-2019.hs
Last active December 19, 2019 07:40
ccc-2019.hs
-- Compilation : ghc ccc2019.hs -o regex
-- Usage : ./regex "a*b" "aaab"
import System.Environment
import System.Exit
main :: IO ()
eq a b | a == '.' = True
@totetmatt
totetmatt / ccc-2019.sh
Created December 19, 2019 09:27
ccc-2019.sh
#!/bin/bash
# Storing the input string
pattern=$1
string=$2
# We will use 2 pointers
ptrPattern=0
ptrString=0
@totetmatt
totetmatt / ccc.cpp
Last active December 29, 2019 19:43
ccc.cpp
// g++ -o ccc ccc.cpp
// ./ccc 'a' 'aacb' && echo 'YES' || echo 'NO'
#include <iostream>
#define ENDSTRING '\0'
#define DOTCHAR '.'
#define STARCHAR '*'
int regex(char *str, char* pattern) {
// We are gonna use the C++ pointer arithmetic to go forward through our strings.
// #Pointer #PointerArithmetic
https://www.youtube.com/playlist?list=PLhM2cOpnyjtYwbqD0LzpqFfIKMBLycsbe
https://www.youtube.com/playlist?list=PLQy7BP5B_ri-0fVxdD5Dj7Glm-PvsocjV
https://www.youtube.com/playlist?list=PLQy7BP5B_ri-s-crnEgeWUwOa7pJNf4tM
@totetmatt
totetmatt / bsearchinsert.sh
Last active January 7, 2020 19:02
bsearchinsert.sh
#!/bin/bash
# set -x
KEY=$1
FILE=$2
# If file doesn't exists
if [ ! -f "$FILE" ]
then
touch $FILE
fi
@totetmatt
totetmatt / yougif.sh
Created January 17, 2020 08:29
Grab a video and create a gif from selected timestamp
# $1 = Video URL
# $2 = Time to start (format 00:00:00)
# $3 = Duration of sample (format 00:00:00)
# $4 = Output file
youtube-dl -f mp4 \
$1 \
-o - \
| ffmpeg -i pipe: \
-ss $2 \
-t $3 \
#version 150
in VertexData
{
vec4 v_position;
vec3 v_normal;
vec2 v_texcoord;
} inData;
out vec4 fragColor;
# crontab -l
59 09 * * 1-5 export DISPLAY=:0.0 && /usr/bin/play.sh
# ^---------- better to wrap the command to a script
# ^------make it launchable without display / terminal
#
# /usr/bin/play.sh
#!/bin/bash
/usr/bin/mplayer -vo null -vc dummy -really-quiet -volume 75 -loop 2 "$(ls /home/totetmatt/Music/JRMelody/* | shuf | head -n 1)" > /dev/null 2>&1
@totetmatt
totetmatt / demo.shader
Created February 20, 2020 12:35
Kodelife shader program
#version 150
in VertexData
{
vec4 v_position;
vec3 v_normal;
vec2 v_texcoord;
} inData;
out vec4 fragColor;