Skip to content

Instantly share code, notes, and snippets.

Avatar
😃

Viktor Lazarev gentoid

😃
View GitHub Profile
View .babelrc
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
]
}
@gentoid
gentoid / main.rs
Last active Jul 29, 2018
Human readable time diff
View main.rs
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);
View 0. Ruby Meta Programming - spells covered.md
  • 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 Aug 23, 2016 — forked from yang-wei/destructuring.md
Elm Destructuring (or Pattern Matching) cheatsheet
View destructuring.md

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 Jun 20, 2016 — 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
View ajax_setup.js
$.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?
View id_ed25519.pub
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHYAMnK0x4q12K7UqeR7sd6joJN9LgGc1d6XQhg/eOUD viktor@gentoo
@gentoid
gentoid / what-forces-layout.md
Created Oct 15, 2015 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.
View what-forces-layout.md

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()
View responsive-font.css
body {
font-size: 5vw;
}
@media (max-width: 700px) {
body {
font-size: 35px;
}
}
@media (min-width: 3000px) {
body {
@gentoid
gentoid / sample.coffee
Created Jun 25, 2015
CoffeeScript + jQuery event handling
View sample.coffee
# 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 :-)
View app.po
# 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"