Skip to content

Instantly share code, notes, and snippets.

@neontorrent
neontorrent / ffmpegs.sh
Created September 23, 2021 04:23
ffmpeg
ffmpeg -i input.mp4 -vf mpdecimate,setpts=N/FRAME_RATE/TB out.mp4
@neontorrent
neontorrent / ChangeDisplaySettings.ps1
Last active July 25, 2021 23:14
ChangeDisplaySettings in C# and Powershell, pass byte array as struct pointer
# Version 1. Unsafe C Style
$cp = [System.CodeDom.Compiler.CompilerParameters]::new()
$cp.CompilerOptions = '/unsafe'
$Display = Add-Type -TypeDefinition @'
using System;
using System.Runtime.InteropServices;
public unsafe class Display
{
[DllImport("User32.dll")]
public static extern bool EnumDisplaySettings(
SortedMap.iterableFactory should be Seq instead of Iterable
Add implicits for IterableFactory objects
MapView.values is not lazy
Monoid
empty
concat
append
Functor
map: (a -> b) -> f a -> f b
Monad
unit
/* Ambiguous
def compare[T1, T2](a: T1, b: T2)(implicit ev: T1 => T2) = compareImpl[T2](ev(a), b)
def compare[T1, T2](a: T1, b: T2)(implicit ev: T2 => T1) = compareImpl[T1](a, ev(b))
def compareImpl[T](a: T, b: T) = a == b
*/
import scala.reflect.runtime.universe._
import scala.reflect.macros.blackbox.Context
import scala.language.experimental.macros
import scala.language.implicitConversions
@neontorrent
neontorrent / perf.md
Last active January 17, 2019 02:40
C++ Performance Tuning Notes

In order to gen call graph in perf:

-fno-omit-frame-butter

#Generate perf.data for executable perf record -g executable #0.5 is a filter?, caller is inverse the graph callstack perf report -g 'graph,0.5,caller'

Prevent optimizer to remove code:

@neontorrent
neontorrent / cpp_flags
Created January 12, 2019 20:33
GCC flags
-fno-omit-frame-pointer
-std=c++17
-pedantic
@neontorrent
neontorrent / auto_ptr.cpp
Created January 10, 2019 15:50
Simple Auto Pointer Impl
std::unordered_map<void*, size_t> *auto_ref_cnt;
template<typename T>
class AutoPtr {
T * data;
public:
AutoPtr() = delete;
AutoPtr(T* data): data(data) {
if(auto_ref_cnt == nullptr) {
auto_ref_cnt = new std::unordered_map<void*, size_t>;
@neontorrent
neontorrent / helper.cpp
Last active January 4, 2019 21:57
C++: is_iterable, map
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <type_traits>
template <typename T, typename = void>
struct is_iterable : std::false_type {};
template <typename T>
@neontorrent
neontorrent / boilerplates.cpp
Last active January 4, 2019 18:52
Boilerplates for C++
//Template Type Check
template<typename T, typename F,
typename = std::enable_if_t<std::is_invocable<F, T>::value> >
void foo()
{}
template<typename T, typename F,
typename = typename std::enable_if<std::is_invocable<F, T>::value>::type >
void foo()
{}