Skip to content

Instantly share code, notes, and snippets.

View joakimriedel's full-sized avatar

Joakim Riedel joakimriedel

View GitHub Profile
@adrienbrault
adrienbrault / llama2-mac-gpu.sh
Last active April 22, 2024 08:47
Run Llama-2-13B-chat locally on your M1/M2 Mac with GPU inference. Uses 10GB RAM. UPDATE: see https://twitter.com/simonw/status/1691495807319674880?s=20
# Clone llama.cpp
git clone https://github.com/ggerganov/llama.cpp.git
cd llama.cpp
# Build it
make clean
LLAMA_METAL=1 make
# Download model
export MODEL=llama-2-13b-chat.ggmlv3.q4_0.bin
@uladz-zubrycki
uladz-zubrycki / EFCoreHacks.cs
Created October 14, 2021 09:20
EFCore 3 full scan workaround
// Workaround for https://github.com/dotnet/efcore/issues/17936
// Requires https://www.nuget.org/packages/LinqKit/
// EFCoreHacks.Rewrite is a custom "expression optimizer" for LinqKit, which should be set to LinqKitExtension.QueryOptimizer
// I do it in my DbContext static constructor. It allows us to use SelectEF and FirstOrDefaultEF extensions methods,
// which are to be rewritten before the expression is passed to EF query translator. Those force EF to use OUTER APPLY with proper predicate.
//
// SelectEF(exp) -> .Select(exp).Take(Int32.MaxValue).ToArray();
// FirstOrDefaultEF -> .Take(1).ToArray().FirstOrDefault();
//
@joakimriedel
joakimriedel / svgoLoader.ts
Created September 30, 2021 14:50
Plugin for svgo to set fill to currentColor
import svgToMiniDataURI from "mini-svg-data-uri";
import type { Plugin } from "rollup";
import fs from "fs";
import { optimize, OptimizeOptions } from "svgo";
type PluginOptions = { noOptimize?: boolean; svgo?: OptimizeOptions };
//TODO: remove this once https://github.com/vitejs/vite/pull/2909 gets merged
export const svgLoader: (options?: PluginOptions) => Plugin = (
options?: PluginOptions
@joakimriedel
joakimriedel / SvgIcon.vue
Last active June 28, 2022 20:41
Vue component for SVG icons using Vue 3, async import using Vite, and Typescript strict typings
<!-- This script for defining icon sources and type could be put in external ts file -->
<script lang="ts">
/** define all the icons that we want to make available here */
const iconSources = {
signin: () =>
import("@fortawesome/fontawesome-free/svgs/solid/sign-in-alt.svg"),
signout: () =>
import("@fortawesome/fontawesome-free/svgs/solid/sign-out-alt.svg"),
plus: () => import("@fortawesome/fontawesome-free/svgs/solid/plus.svg"),
};
@joakimriedel
joakimriedel / !typed mappers (mapGetters, mapActions, mapMutations, mapState) for vuex 4 and vue 3.md
Last active May 9, 2024 14:40
Strictly typed mappers for vuex 4 and vue 3 using Typescript 4.4+

Vuex 4 is a great companion to Vue 3, but Vuex is falling behind on Typescript support. While waiting for better typing support in Vuex 5 or using Pinia, this wrapper might help.

Using this wrapper will correctly infer arguments and return types on your state, actions, getters and mutations.

It works both within your store(s) and any Vue components where you use the mapActions, mapState, mapGetters or mapMutations helpers from Vuex.

No more any will help you find many errors at compile-time!

@ErikEJ
ErikEJ / IQueryableExtensions.cs
Last active June 14, 2024 19:25
Replacement for EF Core .Contains, that avoids SQL Server plan cache pollution
using System.Linq.Expressions;
namespace Microsoft.EntityFrameworkCore
{
public static class IQueryableExtensions
{
public static IQueryable<TQuery> In<TKey, TQuery>(
this IQueryable<TQuery> queryable,
IEnumerable<TKey> values,
Expression<Func<TQuery, TKey>> keySelector)