Skip to content

Instantly share code, notes, and snippets.

View shepelevstas's full-sized avatar
😁

Shepelev Stas shepelevstas

😁
  • Russia, Krasnoyarsk
View GitHub Profile
@shepelevstas
shepelevstas / deep_equal.js
Created August 20, 2022 22:35
deep equal js
function deepEq( x, y, propertyList, pred ) {
if ( x === y ) return true;
// if both x and y are null or undefined and exactly the same
if ( ! ( x instanceof Object ) || ! ( y instanceof Object ) ) return false;
// if they are not strictly equal, they both need to be Objects
if ( x.constructor !== y.constructor ) return false;
// they must have the exact same prototype chain, the closest we can do is
// test there constructor.
@shepelevstas
shepelevstas / deep_copy.js
Last active August 20, 2022 23:01
deep copy js
// correct object cloning
function clone(obj, fields) {
if (null == obj || "object" != typeof obj) return obj;
if (obj.constructor == File && obj.size)
return obj
var copy = obj.constructor();
if (fields){
for (let i of fields)
if (obj.hasOwnProperty(i))
"workbench.colorCustomizations": {
"[Eiffel]": {
"editorGroupHeader.noTabsBackground": "#eee",
},
},
"editor.tokenColorCustomizations": {
"[Eiffel]": {"textMateRules": [
{"settings":{"foreground":"#000"},"scope":[
"invalid.illegal.unrecognized-tag.html",
@shepelevstas
shepelevstas / settings.json
Created August 3, 2022 17:18
Vscode light theme Codepen
{
"workbench.colorCustomizations": {
"[Default Light+]": {
"panel.background": "#eee",
"terminal.background": "#fff",
"editorPane.background": "#eee",
"editorGutter.background": "#eee",
"editorGroupHeader.noTabsBackground": "#eee",
"list.inactiveSelectionBackground": "#cde",
"sideBar.border": "#ccc",
from django.db.models import Sum
from .models import Item
# for django < 1.8
group_sums = Item.objects.filter(deleted=None).values('user').annotate(sum=Sum('price', field='price*quantity'))
# group_sums :: [{'user': 123, 'sum': 9999}]
# values + annotate => GROUP BY in sql
@shepelevstas
shepelevstas / Main.elm
Last active July 19, 2022 12:45
Kadr widget
module Main exposing (main)
import Browser
import Browser.Events as Events
import Browser.Dom as Dom
import Html exposing (Html, button, div, text)
import Html.Attributes exposing (class, style, id)
import Html.Events exposing (onClick)
import Html.Events.Extra.Mouse as Mouse
import Json.Decode as D
@shepelevstas
shepelevstas / counter.html
Created April 8, 2022 06:57
counter up to big int
<script>
;window.addEventListener('load', () => {
/// пример <span data-count-from='0' data-count-to='8000000' data-count-duration='2000'>8.000.000</span>
function onceVisible(el, callback) {
new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
callback(el, entry, observer)
observer.disconnect()
}
@shepelevstas
shepelevstas / onVisible.js
Created April 7, 2022 10:47
html element becomes visible
function onVisible(el, once=true) {
return new Promise((done, fail) => {
new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.intersectionRatio > 0) {
done(el, observer, entry)
if (once) {observer.disconnect()}
}
})
}).observe(el)
@shepelevstas
shepelevstas / settings.json
Last active September 2, 2021 17:01
Emerald VS Code Color Theme
{
"workbench.colorCustomizations": {
"[Visual Studio Dark]": {
// Emerald 028a0f
// Pistachio b2d3c2
// Fern 5dbb63
// Parakeet 03c04a
"editor.background": "#5dbb63",
"editor.foreground": "#fffc",
"editorIndentGuide.background": "#0001",
@shepelevstas
shepelevstas / Main.elm
Created April 15, 2021 21:59
Recursive widgets rendering from son
module Main exposing (main)
import Browser
import Html exposing (Html, button, div, text, input, label, button)
import Html.Attributes exposing (type_, class, value, name, checked)
import Html.Events exposing (onClick)
type alias Model =
{ count : Int, fields: List Field }