Skip to content

Instantly share code, notes, and snippets.

function Foobar(v) {
v(this.resolve.bind(this), this.error.bind(this))
}
Foobar.prototype.resolve = function(v) {
this.value = v
this.resolveFunction(v)
}
Foobar.prototype.error = function(v) {
@codeman869
codeman869 / mergesort.swift
Created November 21, 2018 20:17
A simple mergesort in swift
func mergesort<T: Comparable>(_ input: [T] ) -> [T] {
guard input.count > 1 else {
return input
}
let midPoint:Int = input.count / 2
let tempLeft = Array(input[..<midPoint])
let tempRight = Array(input[midPoint...])
let left = mergesort(tempLeft)
@codeman869
codeman869 / main
Last active October 15, 2018 18:39
FragrantWryText created by codeman869 - https://repl.it/@codeman869/FragrantWryText
ELF>p@`V@8 @*)@@@��888�2�2�<�L�L��<�L�L��TTTDDP�tdd2d2d2TTQ�tdR�td�<�L�L@@/lib64/ld-linux-x86-64.so.2GNUGNU���� � �˔x�2M�"') D ` z"� ���
#)>DN
@codeman869
codeman869 / index.js
Created October 12, 2018 22:43
SphericalImpossibleFormats created by codeman869 - https://repl.it/@codeman869/SphericalImpossibleFormats
const isPrime = (num) => {
switch(num) {
case 1:
return false
case 2:
return true
case 3:
return true
default:
break
@codeman869
codeman869 / deranged.abap
Created September 6, 2018 17:52
Derangement Subfactorial - counts number of object permutations of a given set without any objects in their original position
FUNCTION z_derangement.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(I_NUMBER) TYPE NUM
*" EXPORTING
*" VALUE(EX_NUMBER) TYPE ZBIG
*"----------------------------------------------------------------------
ASSERT i_number > 0.
#include "stdafx.h"
#include <vector>
#include <iterator>
#include <iostream>
using namespace std;
const double pi = 3.14159265358979;
class Circle {
public:
Circle(int rad) : radius(rad) {
#include "stdafx.h"
#include <vector>
#include <iterator>
#include <iostream>
using namespace std;
typedef vector<int>::iterator itr;
itr partition(itr, itr);
@codeman869
codeman869 / quicksort.cpp
Last active April 3, 2018 19:22
Quicksort in C++ for vector<int>
#include "stdafx.h"
#include <vector>
#include <iostream>
using namespace std;
int partition(vector<int>&, int, int);
void quicksort(vector<int>& tobeSorted, int lo, int hi) {
if (lo < hi) {
@codeman869
codeman869 / brain-fuck.js
Created June 8, 2017 03:37
Brainfuck interpreter written in Javascript
function brainLuck(code, input){
var codeArray = code.split("");
var memory = [0];
var codePtr = 0;
var memPtr = 0;
var inputPtr = 0;
var output = [];
//debugger;
while(codePtr < codeArray.length) {
var value = memory[memPtr];
// Write some awesome Swift code, or import libraries like "Foundation",
// "Dispatch", or "Glibc"
func interpreter(code: String, iterations: Int, width: Int, height: Int) -> String {
guard width > 0 || height > 0 else {
return ""
}
//print("code: \(code), height: \(height), width:\(width), iterations: \(iterations)")
let validCommands : [Character] = ["n", "s", "e", "w", "*", "[", "]"]
var memory = Array(repeating: Array(repeating: 0, count: width), count: height)
var memX = 0, memY = 0