Skip to content

Instantly share code, notes, and snippets.

@localhostdotdev
localhostdotdev / gittree.md
Created February 25, 2019 13:13
Like `tree` but takes into account the `.gitignore` file

Made a working one with only ruby and git as a dependency:

One liner to type in irb:

def format(file); split = file.split('/'); return file unless split.size > 1; "│  " * (split.size - 2) + "└── " + split.last; end; def list(dir, start: true); puts dir if start; `git ls-tree master "#{dir}" --name-only`.split("\n").sort.each { |line| split = line.split('/'); puts format(line); list(line + '/', start: false) if File.directory?(line)  }; end; list('.')

And as a more proper script:

@localhostdotdev
localhostdotdev / 20.json
Last active July 22, 2019 20:48
Twitter datacenters by id, located by tweets around with the corresponding ids, best viewed on Github Desktop version (not on mobile's github). Each file name is a datacenter id, the points on the map are the different users who used that datacenter
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

ABAP

{% def random n:1 %}
  {% if n|equal 1|or (n|is_a "float") %}
    {{|rand|times n}}
  {% else %}
    {{|rand|times n|round}}
  {% end %}
{% end %}
{ function j(string) { return string.join('') } }
template =
(
interpolation /
tag /
$(!interpolation !tag .)
)+
ws = (" " / "\n")*
text <- string:blob (object:object text:text
/ tag:tag text:text
% / open_tag:open_tag text:text
/ open_object:open_object text:text)?
blob <- (!open_object !open_tag .)*
object <- open_object:open_object space (argument:argument filters:filters / argument:argument)? space close_object:close_object
tag <- cond_if_tag / cond_unless_tag / cond_case_tag / assign_tag / comment_tag
@localhostdotdev
localhostdotdev / post fetch rails json with csrf token.coffee
Last active May 12, 2019 00:11
post fetch rails json with csrf token
post = (url, body) ->
token = document.querySelector('meta[name="csrf-token"]').attributes.content.value
fetch("#{url}.json",
method: "POST"
mode: "cors"
cache: "no-cache"
credentials: "same-origin"
headers:
"Content-Type": "application/json"
@localhostdotdev
localhostdotdev / hex-to-cterm.rb
Created May 11, 2019 18:55
hex color to cterm color, mainly for vim to translate hex color to cterm colors in colorscheme
#!/usr/bin/env ruby
if ARGV.size != 1 || ARGV[0] !~ /#[0-9a-fA-F]{3,6}/
abort "USAGE: hex-to-cterm HEX"
end
def hex_to_rgb(hex)
rgb = hex.gsub('#', '').chars
if rgb.size == 3
Blink
Blink>Bluetooth
Blink>CSS
Blink>Canvas
Blink>DOM
Blink>Network>FetchAPI
Blink>Paint
Blink>PerformanceAPIs
Blink>Scroll
Blink>Storage>FileSystem
@localhostdotdev
localhostdotdev / graph + ruby code.md
Created May 7, 2019 00:03
Ruby HATBM - Negative Filtering behaving strange, graph https://stackoverflow.com/a/56006045/10993539

graphiz nodes

puts Contact.all.map { |c| "C#{c.id} [style=filled,color=greenyellow]"  } +
  Book.all.map { |b| "B#{b.id} [style=filled,color=lightcyan]" } +
  BookContact.all.map { |bc| "C#{bc.contact_id} -> B#{bc.book_id}" }
digraph G {
  • there is a fixed width/height rectangle board
  • players are circles
  • every player start at size 10 let's say
  • when somebody goes off the board (player B) the last player (A) who touched player B gets half of its "weight" added
    • perimeter is pi * r**2
    • so the new perimeter is (pi * rA**2) + (pi * rB**2)/2
    • new radius is pi * r**2 = (pi * rA**2) + (pi * rB**2)/2
    • r = sqrt(((pi * rA**2) + (pi * rB**2)/2)/2)
  • acceleration is proportional to weight (so the larger the slower)
  • when touching another player forces are distributed by weight (e.g. small player can't push large player much)