Skip to content

Instantly share code, notes, and snippets.

View Walkeryr's full-sized avatar

Yuri Khamzyaev Walkeryr

View GitHub Profile
@Walkeryr
Walkeryr / 2022-11-29-0.md
Last active November 29, 2022 15:20
2022-11-29 How to debug Elm code

Debug.log returns passed value, so it can be used in between chain of function calls:

encodePerson <| Debug.log "person" <| mergeFn person
@Walkeryr
Walkeryr / Jest testing snippets.md
Created May 31, 2022 21:38
Jest testing snippets

Mocking console.error

Requires jsdom

describe("module", () => {
  beforeAll(() => {
    jest.spyOn(console, "error").mockImplementation(() => {});
  });
@Walkeryr
Walkeryr / ch1-binarySearch.ts
Last active August 17, 2020 19:42
Exercises from the "Grokking Algorithms" book
function binarySearch(list: number[], item: number) {
let low = 0
let high = list.length - 1
while (low <= high) {
let mid = Math.floor((low + high) / 2)
let guess = list[mid]
if (guess === item) {
return mid
@Walkeryr
Walkeryr / rem-to-px.js
Created February 25, 2020 08:55
Script to convert all rems to pixels
var fs = require('fs');
let doc = fs.readFileSync('dist/css/app.b528a7e0.css', 'utf8');
console.log(doc.replace(/(:|\s?){1}([0-9-]*\.?[0-9]*)(rem)/g, function (match, delimeterGroup, numberGroup, sizeGroup, offset, string) {
let pixelSize = Number(numberGroup) * 16
if (delimeterGroup === ':') {
return `:${pixelSize}px`
} else if (delimeterGroup === ' ') {
@Walkeryr
Walkeryr / solution.js
Created May 11, 2018 21:54
[Project Euler] Problem 1 — Multiples of 3 and 5.
let sum = 0;
for (let i = 0; i < 1000; i++) {
if (i % 3 === 0 || i % 5 === 0) {
sum += i;
}
}
console.log(sum)
@Walkeryr
Walkeryr / .block
Last active January 27, 2018 11:00
Binary search visualization
license: MIT
height: 400
border: no
@Walkeryr
Walkeryr / .block
Last active January 14, 2018 16:46
d3.geoPath + retina canvas
license: gpl-3.0
height: 600
border: no
@Walkeryr
Walkeryr / .gitignore
Last active September 3, 2017 12:06
TAOCP — 1.1.1E: Euclid‘s Algorithm
__pycache__
def detect_mobile(f):
def wrapped(*args, **kwargs):
request = args[0]
if request.mobile and not request.tablet:
path_lang = request.path.find('/en/')
if path_lang != -1 and request.path.find('/mobile/') == -1:
return HttpResponseRedirect('/en/mobile' + request.path[3:])
return HttpResponseRedirect('/mobile' + request.path)
return f(*args, **kwargs)
var foundFlat = null;
var foundFloor = null;
_.each(json, function(bulk) {
_.each(bulk.sections, function(section) {
_.each(section.floors, function(floor, floorData) {
if (floorData.flats) {
_.each(floorData.flats, function(flat) {
if (flat.id === flatId) {
foundFlat = flat;