Skip to content

Instantly share code, notes, and snippets.

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)

content_for(:false) { false }

  • content_for?(false) false
  • content_for(false) nil
  • yield(false) ""

content_for(:true) { true }

  • content_for?(true) false
Error detected while processing function DistractFree#DistractFreeToggle[32]..<SNR>43_
SaveRestore[30]..<SNR>43_ResetHi:
line 8:
E416: missing equal sign: cleared
E416: missing equal sign: cleared
E416: missing equal sign: cleared
-------------
:DistractFreeToggle Error detected while processing function DistractFree#DistractFreeToggle[32]..<SNR>39_SaveRestore[30]..<SNR>39_ResetHi: