Skip to content

Instantly share code, notes, and snippets.

# prevent core:copy if and only if there's one selection in
# the active editor (mini or not) and its length equals 0
atom.commands.add 'atom-text-editor', 'core:copy', (e) ->
editor = e.currentTarget.getModel()
# do nothing if there's more than 1 selection
return if editor.getSelectedBufferRanges().length > 1
# get the starting and ending points of the selection
{start, end} = editor.getSelectedBufferRange()
Python (3) to (Common) Lisp feature comparison
Memory model & typing:
CL & Python are both managed-memory languages.
Both are also dynamically-typed languages with strong type systems (no implicit type coercion), although Python's design leans toward "duck" typing, and CL's does not.
@commander-trashdin
commander-trashdin / decompose.lisp
Last active July 14, 2019 23:52
doin decomposition
(macrolet ((addiv (d)
`(if (gethash ,d table)
(incf (gethash ,d table))
(setf (gethash ,d table) 1))))
(defun %decompose (n table)
(cond
((= n 1) table)
((<= n 3) (addiv n)
table)
((evenp n) (addiv 2) (%decompose (/ n 2) table))
@commander-trashdin
commander-trashdin / rmk.lisp
Created October 16, 2019 15:58
mah upgrad
;;; You probably wan to add some types to all of this. But later.
(defun check-collision (item-a item-b)
(and
(< (gamekit:x (pos item-a)) (+ (gamekit:x (pos item-b)) (gamekit:x (size item-b))))
(< (gamekit:y (pos item-a)) (+ (gamekit:y (pos item-b)) (gamekit:y (size item-b))))
(> (+ (gamekit:x (pos item-a)) (gamekit:x (size item-a))) (gamekit:x (pos item-b)))
(> (+ (gamekit:y (pos item-a)) (gamekit:y (size item-a))) (gamekit:y (pos item-b)))))
@commander-trashdin
commander-trashdin / deque.cpp
Last active October 18, 2019 19:36
Makin' ma deq
#pragma once
#include <initializer_list>
#include <algorithm>
#include <deque>
#include <memory>
struct Block {
int& operator[](size_t index) {
return data_[index + start_];
Deque has constructors
-------------------------------------------------------------------------------
/home/aun/SDA/shad-cpp0/deque/test.cpp:23
...............................................................................
/home/aun/SDA/shad-cpp0/deque/test.cpp:23: FAILED:
{Unknown expression after the reported line}
due to a fatal error condition:
SIGSEGV - Segmentation violation signal
==8770==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000420 at pc 0x564675a30975 bp 0x7fff37d52420 sp 0x7fff37d52418
READ of size 8 at 0x602000000420 thread T0
#0 0x564675a30974 in std::enable_if<std::__and_<std::__not_<std::__is_tuple_like<Block*> >, std::is_move_constructible<Block*>, std::is_move_assignable<Block*> >::value, void>::type std::swap<Block*>(Block*&, Block*&) (/home/aun/SDA/shad-cpp0/asan_build/test_deque+0x579974)
#1 0x564675a2cfcf in std::unique_ptr<Block, std::default_delete<Block> >::reset(Block*) (/home/aun/SDA/shad-cpp0/asan_build/test_deque+0x575fcf)
#2 0x564675a29815 in std::unique_ptr<Block, std::default_delete<Block> >::operator=(std::unique_ptr<Block, std::default_delete<Block> >&&) (/home/aun/SDA/shad-cpp0/asan_build/test_deque+0x572815)
#3 0x564675a277ab in Deque::Reserve(unsigned long) (/home/aun/SDA/shad-cpp0/asan_build/test_deque+0x5707ab)
#4 0x564675a27b81 in Deque::Realloc() (/home/aun/SDA/shad-cpp0/asan_build/test_deque+0x570b81)
#
@commander-trashdin
commander-trashdin / .cpp
Created October 31, 2019 22:38
scheme_parser
#pragma once
#include <memory>
#include </home/aun/SDA/shad-cpp0/scheme-tokenizer/tokenizer.h>
enum class Types { cellType, numberType, symbolType };
class Object {
public:
@commander-trashdin
commander-trashdin / .cpp
Last active November 6, 2019 13:13
heap
#include <iostream>
#include <vector>
#include <string>
#include <utility>
template <class T, class Predicate>
class Heap {
public:
void Heapify(size_t position) {
size_t left_pos = Left(position);
#pragma once
#include <memory>
class Any {
public:
Any() = default;
template <class T>
Any(T value) : ptr_(std::make_unique<Derived<T>>(std::move(value))) {