Skip to content

Instantly share code, notes, and snippets.

var fn = function(){};
module.exports = {
Body: fn,
Spring: fn,
Material: fn,
ContactMaterial: fn,
DistanceConstraint: fn,
GearConstraint: fn,
LockConstraint: fn,
PrismaticConstraint: fn,
@ldd
ldd / rev.js
Last active November 5, 2017 03:55
reverse unicode strings
var rSymbolMarks = /(<%= allExceptCombiningMarks %>)(<%= combiningMarks %>+)/g;
var rSurrogatePair = /([\uD800-\uDBFF])([\uDC00-\uDFFF])/g;
var reverse = s => s
.replace(rSymbolMarks, ($0, $1, $2) => `${reverse($2)}${$1}`)
.replace(rSurrogatePair, '$2$1')
.split('')
.reverse()
.join('')
@ldd
ldd / day2.js
Created December 4, 2017 14:21
Advent of code - day 2
// day 2
const day2part1 = s => s
.split("\n")
.map(el=> {
const row = el.split(/\s/);
return Math.max(...row) - Math.min(...row);
})
.reduce((p,n)=>p+n,0)
const day2part2 = s => s
@ldd
ldd / day_one.ex
Created December 4, 2017 14:23
Advent of code - Day 1
defmodule ElixirPlayground.DayOne do
@input "./lib/elixir_playground/input/day1.txt"
defp parseInput do
@input
|> File.read!
|> String.trim
|> Kernel.to_charlist
end
@ldd
ldd / day1.js
Created December 4, 2017 14:25
Advent of code - Day 1 (javascript)
// day 1
const day1part1 = s => s
.split('')
.filter((el,i,A)=>(el===A[(i+1) % A.length] ))
.reduce((p,n)=>p+(+n),0)
const day1part2 = s => s
.split('')
.filter((el,i,A)=>(el===A[(i+A.length/2) % A.length]))
.reduce((p,n)=>p+(+n),0)
@ldd
ldd / ghost.js
Last active July 23, 2019 22:39
cute ghost idea
//////////////////
// basic Trie implementation
//////////////////
function Trie() {
this.head = { key: '', children: {} }
}
Trie.prototype.add = function (key) {
@ldd
ldd / chess_ex.js
Created July 31, 2019 22:41
Chess checker
function encode(p, p2) {
let t = 0;
t = (t << 6) | p;
t = (t << 6) | p2;
return t;
}
function decode(s) {
return [s & (2 ** 6 - 1), s >> 6];
}
@ldd
ldd / linked_list.c
Created August 5, 2019 03:59
double linked list with XOR
#include<stdlib.h>
#include<stdio.h>
struct Node {
int data;
struct Node *both;
};
// https://stackoverflow.com/a/26569748
struct Node * xor(struct Node *m, struct Node *n){
@ldd
ldd / ttf-to-png.md
Created February 26, 2020 01:37
Convert ttf to png

steps

  • get a valid ttf file, or assets like this one
  • get alphabet, for example:
     const s = "";
     for(let i=0; i < 76; i++1){
     if(i % 16 === 0) s += "\n";
     s += String.fromCharCode(47 + i);

}

@ldd
ldd / formatted_date.rb
Created April 8, 2020 18:19
jekyll plugin to format date
module Jekyll::CustomFilter
def formatted_date(date)
# date = Time.parse(string_date)
ending = 'th'
case date.day % 10
when 1
ending = 'st'
when 2
ending = 'nd'
when 3