Skip to content

Instantly share code, notes, and snippets.

View crosstyan's full-sized avatar

Crosstyan crosstyan

View GitHub Profile
#! /usr/bin/env python
from turtle import circle
import cv2
import sys
import numpy as np
import typing
from typing import Tuple
import collections
# See also
@crosstyan
crosstyan / iter.c
Last active September 4, 2022 13:51
an example to use iterator instead of ugly fuck i. See also https://crypto.stanford.edu/~blynn/c/cruft.html
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#define REP(x, n) for (int x = 0; x < n; x++)
#define REP1(x, n) for (int x = 1; x <= n; x++)
#define NELEM(a) (sizeof(a)/sizeof(a[0]))
struct test_t {
@crosstyan
crosstyan / mongo-cheatsheet.md
Last active October 24, 2022 07:34 — forked from dittmaraz/mongo-cheatsheet.md
MongoDB/Docker Cheatsheet

Mongo/Docker Cheatsheet

To download the latest image:

$ docker pull mongo:latest

To run a mongo container with detached mode(-p) and with ports mapped (-p 27017-27017:27017-27019) and named (--name mongodb):

$ docker run -d -p 27017-27019:27017-27019 --name mongodb mongo:latest

@crosstyan
crosstyan / deadsnakes-python39-ubuntu-bionic.md
Created May 31, 2022 07:11
Deadsnakes python 3.9 on Ubuntu 18.04 LTS

Deadsnakes python 3.9 on Ubuntu 18.04 LTS

NOTE: Recently switched back to using pyenv so I can run multiple python versions without losing my mind. It only takes a few minutes to set up, but provides the flexibility I need without making things too complicated. See my gist, Manage python versions on Linux with pyenv for more.

The deadsnakes PPA make the latest stable versions of python available on Ubuntu 18.04 LTS (3.9 is already in the official apt repo for 20.04). I now find it preferable to installing from source.

The following was tested on a Ubuntu 18.04.5 LTS desktop with python 3.6.9 as the system python version ("python3").

The latest python available from deadsnakes as of July, 2021 is 3.9.6.

Prerequisites

@crosstyan
crosstyan / 00-NOTES.md
Created April 28, 2022 17:06 — forked from krisleech/00-NOTES.md
Notes on Clojure ring handlers and middleware

Ring handler a function which accepts a request (map) and returns a response (map).

Ring middleware

function (handler, &args -> function(request -> response) because it is a closure handler and &args are in scope within the returned handler function.

a function which accepts a "next handler" (the next handler in the chain) + any extra arguments and returns a handler (function), which will accept a request and return a response.

@crosstyan
crosstyan / client.py
Created April 27, 2022 12:46 — forked from bashkirtsevich/client.py
asyncio UDP client
import asyncio
class EchoClientProtocol:
def __init__(self, message, loop):
self.message = message
self.loop = loop
self.transport = None
def connection_made(self, transport):
self.transport = transport
;; in 1.0a4 no need of bracket
(import numpy :as np
pandas :as pd
random [random]
functools [reduce]
seaborn :as sns
matplotlib.pyplot :as plt
scipy.stats [norm]
os [listdir])
@crosstyan
crosstyan / 25t.csv
Last active April 13, 2022 05:52
example using hy to plot some data. x is the domain and y is the number in that bin.
x y
318 37
319 58
320 130
321 142
322 252
323 458
324 530
325 700
326 688
@crosstyan
crosstyan / project.clj
Created March 31, 2022 17:21
an example of clojure udp server using aleph
(defproject udp-server "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
:url "https://www.eclipse.org/legal/epl-2.0/"}
:dependencies [[org.clojure/clojure "1.10.3"]
[aleph "0.4.6"]
[org.clojure/core.match "1.0.0"]]
:repl-options {:init-ns udp-server.core})
@crosstyan
crosstyan / A-sum-higher-kinds.clj
Created March 23, 2022 15:31 — forked from ckirkendall/A-sum-higher-kinds.clj
Polymorphism - Summation of Higher Kinds(Clojure, Ocaml, Haskell, Scala, Java).
(defrecord Tree [left elm right])
(defprotocol Monoid
(append [a b] )
(identity [a] ))
(defprotocol Foldable
(foldl [l f i])
(mfirst [l]))