Skip to content

Instantly share code, notes, and snippets.

Avatar

Oleg Dashevskii be9

View GitHub Profile
@be9
be9 / certpinning.js
Last active Nov 5, 2018
Puppeteer: accessing SSL cert data
View certpinning.js
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;
View haha.rb
class BaseScraper
def login
# логинится на сайте. сессия должна быть сохранена (в ООП подходе она хранится внутри объекта)
end
def get_data1(arg)
# выдирает данные одного вида, используя сохраненную сессию и обновляя её
end
def get_data2(arg1, arg2)
@be9
be9 / promises.ts
Created Feb 27, 2017
An illustration of how ES6 promises work
View promises.ts
async function zero(): Promise<number> {
console.log('zero');
return 0;
}
async function add(origP: Promise<number>, inc: number): Promise<number> {
return inc + await origP;
}
View build.boot
(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"]
View gc_test.rb
def fill(a)
100_000.times {
a << rand(10000).to_s * 100
}
end
def aa
ary = []
fill(ary)
View cache.rake
namespace :cache do
desc "Clears Rails cache"
task :clear => :environment do
Rails.cache.clear
end
end
@be9
be9 / bright.rb
Created Apr 30, 2015
Brightness function
View bright.rb
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
View serialize.h
/**
* 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,
View Gemfile
source 'https://rubygems.org'
gem 'activerecord', '4.2.0'
gem 'sqlite3'
gem 'bcrypt', '~> 3.1.7'