Skip to content

Instantly share code, notes, and snippets.

View michalbcz's full-sized avatar

Michal Bernhard michalbcz

View GitHub Profile
@michalbcz
michalbcz / zbranekvalitne-scraper.js
Last active September 7, 2019 09:10
Puppetteer based nodejs scraper of https://zbranekvalitne.cz/zbrojni-prukaz/testove-otazky. Questions are not categorized by groups. Just all the questions.
const puppeteer = require('puppeteer')
const fs = require('fs')
// this wrapper means immediatelly execute this code
void(async () => {
const url = 'https://zbranekvalitne.cz/zbrojni-prukaz/testove-otazky'
try {
console.log("I am scraping questions from " + url)
const browser = await puppeteer.launch({
@michalbcz
michalbcz / disable-ssl-verification.groovy
Created May 14, 2018 13:01
Java/Groovy disable SSL verification
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.net.URLConnection;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
@michalbcz
michalbcz / gist:a1d4c178b2efb1531a9b8335986959bb
Created January 18, 2018 13:09
java http proxy settings programatically
import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.io.InputStream;
import java.net.Authenticator;
import java.net.InetSocketAddress;
import java.net.PasswordAuthentication;
import java.net.Proxy;
import java.net.SocketAddress;
import java.net.URL;
Verifying my Blockstack ID is secured with the address 14MwVtYYodWwQTrrzaFH3b8v6G4gAmFLZL https://explorer.blockstack.org/address/14MwVtYYodWwQTrrzaFH3b8v6G4gAmFLZL
@michalbcz
michalbcz / flickr-background.js
Last active February 6, 2017 15:22 — forked from krtek/flickr-background.js
Flickr background
"use strict";
var API_KEY = '__API_KEY__';
var PHOTOSET_IDS = ['__ID1__', '__ID2__', '__ID3__'];
var cartagenaApp = angular.module('cartagenaApp');
cartagenaApp.directive('flickrBackground', function(Flickr, $http) {
var _flickrBackground = function($scope, $element) {
var nextPhoto;
@michalbcz
michalbcz / gist:3694f0cc27b71b6a817c5152e3193164
Created January 13, 2017 14:25
java turn off ssl client certification verification
SSLContext sslContext = null;
try {
sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[] { new SSLTrustManger() }, new java.security.SecureRandom());
} catch (Exception e) {
throw new RuntimeException(e);
}
SSLSocketFactory socketFactory = sslContext.getSocketFactory();
@michalbcz
michalbcz / latency.markdown
Created October 10, 2016 06:57 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@michalbcz
michalbcz / gist:8b0bafbfe17c03d30ebd8cec09acecb4
Created October 1, 2016 10:20
gulp auto restart on syntax error
while [ 1 ]; do gulp watch; sleep 3; done
@michalbcz
michalbcz / StringUtils.java
Last active October 26, 2016 09:45
copy pasted strip method from Apache Commons StringUtils - Character#isWhitespace replaced by Character#isSpaceChar (which is unicode aware)
import static org.apache.commons.lang3.StringUtils.isEmpty;
public class StringUtils {
/**
* unicode aware version of Apache Common's StringUtils#strip
*/
public static String strip(String str) {
if (isEmpty(str)) {
return str;
@michalbcz
michalbcz / problem.md
Last active November 10, 2015 16:58
http://www.fogcreek.com/Jobs/SupportEngineer/ - application problem solution

Sort the characters in the following string:

abcdefghijklmnopqrstuvwxyz_

by the number of times the character appears in the following text (descending):

Note: the text scrolls.