Skip to content

Instantly share code, notes, and snippets.

View phoe's full-sized avatar
🤔
:thonk:

Michał "phoe" Herda phoe

🤔
:thonk:
View GitHub Profile
@aras-p
aras-p / preprocessor_fun.h
Last active November 15, 2024 09:22
Things to commit just before leaving your job
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,
@shortsightedsid
shortsightedsid / cl-tcpip.lisp
Last active November 4, 2024 15:18
Short guide to TCP/IP Client/Server programming in Common Lisp using usockets
; Short guide to TCP/IP Client/Server programming in Common Lisp using usockets
;
; The main reason for this guide is because there are very few examples that
; explain how to get started with socket programming with Common Lisp that I
; could understand. After spending a day trying, I finally came up with a small
; bit of code that makes it easy to understand the basics. I've written this
; primarily for myself, but should help others get started as well.
; As usual, we will use quicklisp to load usocket.
@shortsightedsid
shortsightedsid / cl-udpip.lisp
Created October 27, 2014 22:01
Short guide to UDP/IP Client/Server programming in Common Lisp using usockets
; Short guide to UDP/IP Client/Server programming in Common Lisp using usockets
;
; The main reason for this guide is because there are very few examples that
; explain how to get started with socket programming with Common Lisp that I
; could understand.
; After working on a short example on TCP, I found the
; need for a UDP tutorial. So, here goes.
; As usual, we will use quicklisp to load usocket.
@xandkar
xandkar / curry.erl
Last active November 22, 2017 02:55
Automatic currying in Erlang
-module(curry).
-export([curry/1]).
curry(F) ->
{arity, Arity} = erlang:fun_info(F, arity),
curry(F, [], Arity).
curry(F, Args, 0) ->
apply(F, lists:reverse(Args));
@nikodemus
nikodemus / bt.lisp
Last active July 14, 2022 05:46
Showing why conditions are a bad match for doing backtracking -- all you need is CATCH/THROW and a special variable.
;;;; In response to:
;;;;
;;;; http://www.reddit.com/r/lisp/comments/3710zq/directed_procrastination_backtracking_with_the/
;;;; http://directed-procrastination.blogspot.se/2011/05/backtracking-with-common-lisp-condition.html
;;;;
;;;; Demonstrating why one should not use conditions for this kind of stuff,
;;;; instead using the dynamic binding and unwinding facilities on which the
;;;; condition system is built. The author's backtracking system doesn't compare
;;;; badly to Screamer because his is simple: it compares badly because using
;;;; conditions is a bad match for the task.
@nucliweb
nucliweb / Clone-All-Repos-GitHub-Organization.md
Last active September 23, 2021 10:12
Clone all repos from a GitHub organization

Publics repos

With Ruby 1.8 (default version on MacOS) :

sudo gem install json
curl -s https://api.github.com/orgs/[ORGANIZATION]/repos | ruby -rubygems -e 'require “json”; JSON.load(STDIN.read).each {|repo| %x[git clone #{repo["ssh_url"]} ]}'

With Ruby 1.9+, the json library is by default thus you just use :

@josteink
josteink / on_stateful_code.txt
Last active October 21, 2020 05:37
On why stateful code is bad
On why stateful code is bad
===========================
STUDENT: Sir, can I ask a question?
TEACHER: Yes!
STUDENT: How do you put an elephant inside a fridge?
TEACHER: I don't know.
STUDENT: It's easy, you just open the fridge and put it in. I have another question!
TEACHER: Ok, ask.
STUDENT: How to put a donkey inside the fridge?
@serialhex
serialhex / normal-random.lisp
Last active September 14, 2022 15:51
Generate normal (gaussian) random numbers in lisp!
(defun normal-random (mean std-dev)
"Normal random numbers, with the given mean & standard deviation."
(do* ((rand-u (* 2 (- 0.5 (random 1.0))) (* 2 (- 0.5 (random 1.0))))
(rand-v (* 2 (- 0.5 (random 1.0))) (* 2 (- 0.5 (random 1.0))))
(rand-s (+ (* rand-u rand-u) (* rand-v rand-v))
(+ (* rand-u rand-u) (* rand-v rand-v))))
((not (or (= 0 rand-s) (>= rand-s 1)))
(+ mean
(* std-dev
(* rand-u (sqrt (/ (* -2.0 (log rand-s)) rand-s))))))))
@Treeki
Treeki / lzma_sample.cpp
Created May 24, 2017 21:52
simple LZMA SDK compression/decompression example
// note: -D_7ZIP_ST is required when compiling on non-Windows platforms
// g++ -o lzma_sample -std=c++14 -D_7ZIP_ST lzma_sample.cpp LzmaDec.c LzmaEnc.c LzFind.c
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <memory>
#include "LzmaEnc.h"
#include "LzmaDec.h"
@cmer
cmer / haproxy.cfg
Last active September 9, 2024 11:24
Simple, no bullshit TCP port forwarding using HAProxy
listen l1
bind 0.0.0.0:443
mode tcp
timeout connect 4000
timeout client 180000
timeout server 180000
server srv1 host.example.com:9443