Skip to content

Instantly share code, notes, and snippets.

View gentoid's full-sized avatar
😃

Viktor Lazarev gentoid

😃
View GitHub Profile
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
]
}
@gentoid
gentoid / main.rs
Last active July 29, 2018 18:25
Human readable time diff
mod time_diff;
use time_diff::TimeDiff;
fn main() {
let td = TimeDiff::new(1234123);
let td2 = TimeDiff::new(1233);
println!("First diff is {}", td);
println!("Second diff is {}", td2);
println!("Sum of that diffs is {}", td + td2);
  • Dynamic Dispatch
  • Dynamic Method
  • Ghost Methods
  • Dynamic Proxies
  • Blank Slate
  • Kernel Method
  • Flattening the Scope (aka Nested Lexical Scopes)
  • Context Probe
  • Class Eval (not really a 'spell' more just a demonstration of its usage)
  • Class Macros
@gentoid
gentoid / destructuring.md
Created August 23, 2016 12:11 — forked from yang-wei/destructuring.md
Elm Destructuring (or Pattern Matching) cheatsheet

Destructuring(or pattern matching) is a way used to extract data from a data structure(tuple, list, record) that mirros the construction. Compare to other languages, Elm support much less destructuring but let's see what it got !

Tuple

myTuple = ("A", "B", "C")
myNestedTuple = ("A", "B", "C", ("X", "Y", "Z"))

let
  (a,b,c) = myTuple
@gentoid
gentoid / ajax_setup.js
Created June 20, 2016 17:56 — forked from alanhamlett/ajax_setup.js
Sets the X-CSRFToken header for every jQuery ajax non-GET request to make CSRF protection easy. This fixes the example from Django docs here: https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (settings.type == 'POST' || settings.type == 'PUT' || settings.type == 'DELETE') {
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHYAMnK0x4q12K7UqeR7sd6joJN9LgGc1d6XQhg/eOUD viktor@gentoo
@gentoid
gentoid / what-forces-layout.md
Created October 15, 2015 08:45 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
body {
font-size: 5vw;
}
@media (max-width: 700px) {
body {
font-size: 35px;
}
}
@media (min-width: 3000px) {
body {
@gentoid
gentoid / sample.coffee
Created June 25, 2015 14:02
CoffeeScript + jQuery event handling
# 1. trigger events
$(document).trigger 'flash:message', { level: 'error', message: 'There was an error' }
# 2. catch events in another place
$(document)
.on 'flash:message', (e, params) =>
if params.level && params.message
@show params.level, params.message # call 'show' method doing something interesting :-)
@gentoid
gentoid / app.po
Created June 1, 2015 12:39
gettext
# English translations for Retina package.
# Copyright (C) 2015 THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the Retina package.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2015.
#
msgid ""
msgstr ""
"Project-Id-Version: Retina 0.33.2-26-g8a4bb2a\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-06-01 16:37+0400\n"