Skip to content

Instantly share code, notes, and snippets.

@rafald
rafald / Constraints.org
Created November 18, 2019 14:20 — forked from Icelandjack/Constraints.org
Type Classes and Constraints

Reddit discussion.

Disclaimer 1: Type classes are great but they are not the right tool for every job. Enjoy some balance and balance to your balance.

Disclaimer 2: I should tidy this up but probably won’t.

Disclaimer 3: Yeah called it, better to be realistic.

Type classes are a language of their own, this is an attempt to document features and give a name to them.

@rafald
rafald / ffmpeg.md
Created October 19, 2019 18:06 — forked from protrolium/ffmpeg.md
using ffmpeg to extract audio from video files

ffmpeg

Converting Audio into Different Formats / Sample Rates

Minimal example: transcode from MP3 to WMA:
ffmpeg -i input.mp3 output.wma

You can get the list of supported formats with:
ffmpeg -formats

Convert WAV to MP3, mix down to mono (use 1 audio channel), set bit rate to 64 kbps and sample rate to 22050 Hz:

@rafald
rafald / demo.txt
Created March 28, 2018 11:37 — forked from thoughtpolice/demo.txt
Transactional memory on Haswell
/* -------------------------------------------------------------------------- */
gen2 Core i5 (Sandy Bridge):
$ clang -cc1 -version
LLVM (http://llvm.org/):
LLVM version 3.4svn
Optimized build.
Built Oct 13 2013 (18:10:38).
Default target: x86_64-unknown-linux-gnu
Host CPU: corei7-avx
# Copyright Louis Dionne 2013-2017
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
language: c++
sudo: false
# Do not build branches of the form "pr/*". By prefixing pull requests coming
# from branches inside the repository with pr/, this avoids building both the
# branch push _and_ the pull request.
@rafald
rafald / init-ubuntu-haskell.sh
Created August 11, 2017 16:49 — forked from qzchenwl/init-ubuntu-haskell.sh
Install Haskell development environment.
#!/bin/bash
cat << EOF >> $HOME/.bashrc
export PATH="\$HOME/.local/bin:\$HOME/.cabal/bin:/opt/ghc/7.10.2/bin:/opt/cabal/head/bin:\$PATH"
alias tmux="tmux -2"
EOF
cat << EOF > $HOME/.gitconfig
Shuffle Linked List
Delete duplicate characters
Use 3 types of different data structure to delete a list of objects
Reverse the string
What are you going to learn next?
How to reverse a string
Why Microsoft? Why not ***** company?
Tell me about yourself? Weakness/Strength/etc.
How would you implement a caching proxy server ?
Say you’re a cobbler and I want to buy a pair of shoes… what would you do?
s='is_tokenized_Firstname:TKN_NAME is_tokenized_Last_Name:TKN_NAME'
read -r -a words_in <<<"$s" # Read words into array
for word in "${words_in[@]}"; do # Iterate over input
[[ $word = is_tokenized_*:TKN* ]] && { # Check for match
word=${word#is_tokenized_} # Strip prefixes
word=${word%:TKN*} # Strip suffixes
}
printf '%s ' "$word" # Write output
done
printf '\n'
#include <memory>
// compiler calculates concrete number but it is not compile time constant
int main() {
// statefull lambda object next_fib_num
auto next_fib_num = [i=0, j=1]() mutable {
i = std::exchange(j, j+i);
return i;
};
next_fib_num();
# swap 2 values
old = "old"
new = "new"
old, new = new, old
print( old, new)
# formatting
character = 'Neo'
movie = 'Matrix'
//http://melpon.org/wandbox/permlink/YtEl1NtqNHgULC9X
#include <utility>
template <char... chars>
using CharSeq = std::integer_sequence<char, chars...>;
template <typename T, T... chars>
constexpr CharSeq<chars...> operator""_cts() { return { }; }
//NOTE zero storage - only copiler data stractures encode the string, zero runtime overhead - data