Skip to content

Instantly share code, notes, and snippets.

View be9's full-sized avatar

Oleg Dashevskii be9

View GitHub Profile
@be9
be9 / git.bzl
Created June 10, 2024 08:38
Bazel rule to create a git repo dynamically
load("@aspect_bazel_lib//lib:copy_file.bzl", "COPY_FILE_TOOLCHAINS", "copy_file_action")
def _adhoc_git_repository_impl(ctx):
copied_files = []
for s in ctx.files.srcs:
if not s.is_source:
continue # fix if needed
f = ctx.actions.declare_file(ctx.label.name + "/" + s.path)
@be9
be9 / certpinning.js
Last active November 5, 2018 11:38
Puppeteer: accessing SSL cert data
const puppeteer = require('puppeteer');
process.on('unhandledRejection', (reason, p) => {
console.error('Unhandled Rejection at: Promise ', p, ' reason: ', reason);
process.exit(3);
});
(async () => {
let browser;
let exitCode = 0;
class BaseScraper
def login
# логинится на сайте. сессия должна быть сохранена (в ООП подходе она хранится внутри объекта)
end
def get_data1(arg)
# выдирает данные одного вида, используя сохраненную сессию и обновляя её
end
def get_data2(arg1, arg2)
@be9
be9 / promises.ts
Created February 27, 2017 04:11
An illustration of how ES6 promises work
async function zero(): Promise<number> {
console.log('zero');
return 0;
}
async function add(origP: Promise<number>, inc: number): Promise<number> {
return inc + await origP;
}
(set-env!
:source-paths #{"src/cljs" "src/clj"}
:resource-paths #{"html" "sql"}
:dependencies '[[org.clojure/clojure "1.8.0"]
[mount "0.1.9"]
[funcool/suricatta "0.8.1"]
[environ "1.0.2"]
[boot-environ "1.0.2" :scope "test"]
@be9
be9 / gc_test.rb
Last active November 17, 2015 07:41
def fill(a)
100_000.times {
a << rand(10000).to_s * 100
}
end
def aa
ary = []
fill(ary)
@be9
be9 / cache.rake
Last active December 31, 2016 06:43
namespace :cache do
desc "Clears Rails cache"
task :clear => :environment do
Rails.cache.clear
end
end
@be9
be9 / bright.rb
Created April 30, 2015 04:25
Brightness function
def bright?(color)
if color =~ /^#([[:xdigit:]]{2})([[:xdigit:]]{2})([[:xdigit:]]{2})$/
r = $1.to_i(16)
g = $2.to_i(16)
b = $3.to_i(16)
# Use formula to calculate brightness
# http://www.nbdtech.com/Blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx
brightness = Math.sqrt(r*r*0.241+g*g*0.691+b*b*0.068) / 255 * 100.0
/**
* Copyright (c) 2013, Simone Pellegrini All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,