Skip to content

Instantly share code, notes, and snippets.

View pawelniewie's full-sized avatar

Pawel Niewiadomski pawelniewie

View GitHub Profile
@pawelniewie
pawelniewie / valid_pesel.rb
Created March 13, 2017 19:48
Simple PESEL validator
def valid_pesel?(pesel)
false if pesel.size != 11
(a, b, c, d, e, f, g, h, i, j, k) = pesel.chars.map(&:to_i)
checksum = a + 3*b + 7*c + 9*d + e + 3*f + 7*g + 9*h + i + 3*j + k
checksum % 10 == 0
end
no = gets.to_i
@pawelniewie
pawelniewie / app-assets-javascripts-application.js
Created February 5, 2017 11:49
Header/param based sessions for iframes
//= require_self
//= require service_buttons
//= require error_reporting
$(function () {
var token = $('meta[name=token]').attr('content');
AJS.$.ajaxPrefilter(function(options) {
if (token) {
options.url += ~options.url.indexOf('?') ? '&' : '?';
#!/bin/env ruby
require 'json'
require 'time'
cutoff = Time.parse('2016-08-10')
log = JSON.load(ARGF)
entries_per_day = Hash.new{ |hash, key| hash[key] = [] }
@pawelniewie
pawelniewie / address-book.swift
Last active June 8, 2016 20:30
Getting rid of all first.last@domain contacts from your address book and replacing them with proper entries (or merging if that's possible). More on https://pawelniewiadomski.com/2016/06/08/cleaning-addressbook-with-swift-scripting/
#!/usr/bin/env swift
import Cocoa
import AddressBook
var ab = ABAddressBook.sharedAddressBook()
func findByFirstAndLastName(firstName: String, lastName: String) -> [ABRecord] {
let comparison: ABSearchConjunction = CFIndex(kABContainsSubStringCaseInsensitive.rawValue)
@pawelniewie
pawelniewie / ExplicitOrdering.java
Created April 11, 2016 12:44
ExplicitOrdering from Guava that will not throw when element is outside of the initial collection (unknown to the explicit ordering)
/*
* Copyright (C) 2007 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
package main
import (
"os/exec"
"os/user"
"testing"
"net/http"
"io/ioutil"
"fmt"
"github.com/stretchr/testify/assert"
@pawelniewie
pawelniewie / keybase.md
Created June 14, 2014 14:27
keybase.md

Keybase proof

I hereby claim:

  • I am pawelniewie on github.
  • I am pin (https://keybase.io/pin) on keybase.
  • I have a public key whose fingerprint is 0C9C D2EB A851 031D C1F2 C287 40DB DD41 6DBB 69BB

To claim this, I am signing this object:

@pawelniewie
pawelniewie / angular-datetimepicker.js
Created September 14, 2013 15:49
Integrate bootstrap-datetimepicker with AngularJS. More info with a sample markup at http://pawelniewiadomski.pl/post/61211311724/how-to-use-bootstrap-datetimepicker-with-angularjs
'use strict';
angular.module('$strap.directives').directive('bsDatetimepicker', [
'$timeout',
'$strapConfig',
function ($timeout, $strapConfig) {
var isAppleTouch = /(iP(a|o)d|iPhone)/g.test(navigator.userAgent);
var regexpMap = function regexpMap(language) {
language = language || 'en';
return {
'/': '[\\/]',