Skip to content

Instantly share code, notes, and snippets.

@rionmonster
rionmonster / IQueryableExtensions
Last active November 9, 2022 16:39
Resolve the SQL being executed behind the scenes in Entity Framework Core
public static class IQueryableExtensions
{
private static readonly TypeInfo QueryCompilerTypeInfo = typeof(QueryCompiler).GetTypeInfo();
private static readonly FieldInfo QueryCompilerField = typeof(EntityQueryProvider).GetTypeInfo().DeclaredFields.First(x => x.Name == "_queryCompiler");
private static readonly PropertyInfo NodeTypeProviderField = QueryCompilerTypeInfo.DeclaredProperties.Single(x => x.Name == "NodeTypeProvider");
private static readonly MethodInfo CreateQueryParserMethod = QueryCompilerTypeInfo.DeclaredMethods.First(x => x.Name == "CreateQueryParser");
@ip1981
ip1981 / fromBase64.nix
Last active May 2, 2021 17:09
base64 to hex in nix
strBase64:
let
inherit (builtins)
concatStringsSep genList stringLength substring trace ;
base64 = {
# n=0; for l in {A..Z} {a..z} {0..9} + /; do printf '"%s" = %2s; ' $l $n; (( n++ )); (( n % 8 )) || echo; done
"A" = 0; "B" = 1; "C" = 2; "D" = 3; "E" = 4; "F" = 5; "G" = 6; "H" = 7;

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@garbas
garbas / pycharm.nix
Created September 5, 2016 09:32
pycharm
with import <nixpkgs> {}; rec {
pycharm = stdenv.mkDerivation rec {
name = "pycharm-community-mau";
version = "2016.2.2";
src = fetchurl {
url = https://download.jetbrains.com/python/pycharm-community-2016.2.2.tar.gz;
sha256 = "6bf50910355f680983246ab51f7a082ae6f34f799db222986c1c59003bf1dbec";
};
buildInputs = [ jdk makeWrapper ];
installPhase = ''
@rjz
rjz / ngrok_hostname.sh
Created August 9, 2016 16:20
Get ngrok hostname from command line
#!/bin/sh
# ngrok's web interface is HTML, but configuration is bootstrapped as a JSON
# string. We can hack out the forwarded hostname by extracting the next
# `*.ngrok.io` string from the JSON
#
# Brittle as all get out--YMMV. If you're still reading, usage is:
#
# $ ./ngrok_hostname.sh <proto> <addr>
#
@larsrh
larsrh / list.scala
Last active July 22, 2016 07:50
safe head/tail on lists using covariance
// Initial idea courtesy of @dwijnand
// Improved by @fthomas
sealed trait List[+T] {
def head: Option[T]
}
final case class Cons[T](h: T, t: List[T]) extends List[T] {
val head: Some[T] = Some(h)
}
@paulp
paulp / unsoundagain.scala
Created June 3, 2016 23:19
Another in the endless parade.
package p
/** Super basic map/flatMap fusion ADT.
*/
sealed trait View[A] {
def map[B](f: A => B): View[B] = CView(this, Mapped(f))
def flatMap[B](f: A => View[B]): View[B] = CView(this, FlatMap(f))
def foreach(f: A => Unit): Unit = this match {
case IdView(xs) => xs foreach f
import java.util.Optional;
import java.util.function.Function;
class Main {
public static void main(String[] args) {
Optional<String> o = Optional.of("foo");
Function<String, String> f = s -> null;
Function<String, String> g = String::valueOf;
//lawless lolz
// So called van Laarhoven lenses, named after their discoverer, have a number
// of nice properties as explained by Russell O'Connor:
//
// http://r6.ca/blog/20120623T104901Z.html
//
// Unfortunately their typing (in Haskell)
//
// type Lens s t a b = forall f. Functor f => (a -> f b) -> (s -> f t)
//
// seems to be well outside of what can be achieved in F#.
@agramajo
agramajo / test_requests.py
Created April 18, 2016 13:57
set source ip address
import socket
import requests
real_create_conn = socket.create_connection
#diferentes ips que salen por diferentes enlaces
ip1 = '192.168.1.2'
ip2 = '192.168.1.3'
#forzamos la ip1