Skip to content

Instantly share code, notes, and snippets.

Pawel Niewiadomski pawelniewie

View GitHub Profile
@pawelniewie
pawelniewie / valid_pesel.rb
Created Mar 13, 2017
Simple PESEL validator
View valid_pesel.rb
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 Feb 5, 2017
Header/param based sessions for iframes
View app-assets-javascripts-application.js
//= 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('?') ? '&' : '?';
View parse_day_one_json.rb
#!/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 Jun 8, 2016
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/
View address-book.swift
#!/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 Apr 11, 2016
ExplicitOrdering from Guava that will not throw when element is outside of the initial collection (unknown to the explicit ordering)
View ExplicitOrdering.java
/*
* 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
View nginx_test.go
package main
import (
"os/exec"
"os/user"
"testing"
"net/http"
"io/ioutil"
"fmt"
"github.com/stretchr/testify/assert"
View osx-for-hackers.sh
#!/bin/sh
# Some things taken from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Set the colours you can use
black='\033[0;30m'
white='\033[0;37m'
red='\033[0;31m'
green='\033[0;32m'
View 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:

View angular-datetimepicker.js
'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 {
'/': '[\\/]',
You can’t perform that action at this time.