Skip to content

Instantly share code, notes, and snippets.

View jan-swiecki's full-sized avatar

Jan Święcki jan-swiecki

View GitHub Profile
@jan-swiecki
jan-swiecki / go.bat
Created September 5, 2012 16:06
cd + change drive letter, for windows.
@echo off
REM put this file in C:/Windows
REM then if you are in `d:/abc/cdf` and type `go e:/xxx` in cmd.exe, you will go there :)
cd %~f1
%~d1
@jan-swiecki
jan-swiecki / FizzBuzz.java
Created November 18, 2012 19:14
Java FizzBuzz
class FizzBuzz
{
public static void main(String[] args)
{
for(int i = 1; i <= 100; i++)
{
String str = "";
if(i%3 == 0) str += "Fizz";
if(i%5 == 0) str += "Buzz";
@jan-swiecki
jan-swiecki / onFileChange.js
Last active March 4, 2016 14:16
NodeJS `fs.watch` wrapper that checks file SHA1 and prevents multiple callback calls.
/**
* fs.watch wrapper that checks file SHA1
* and prevents multiple callback calls.
*
* Related: http://stackoverflow.com/q/12978924/1637178
*
* Usage is the same as fs.watch
*
* var onFileChange = require("./onFileChange.js");
*
@jan-swiecki
jan-swiecki / bcomp-diff.bat
Last active December 26, 2015 14:18
Beyond Compare 3 SVN diff and merge windows batch scripts
@ECHO OFF
REM Source: http://svnbook.red-bean.com/en/1.7/svn.advanced.externaldifftools.html
SET DIFF="bcomp.exe"
SET LEFT=%6
SET RIGHT=%7
%DIFF% %LEFT% %RIGHT%
@jan-swiecki
jan-swiecki / asyncLoop.js
Created May 21, 2014 09:49
asyncLoop.js
function asyncLoop(index, callback) {
if(index+1) {
setTimeout(function() {
callback(index);
asyncLoop(index-1, callback);
}, 10);
}
}
// sync
-- Write a program that outputs all possibilities to put + or - or nothing between the numbers 1, 2, ..., 9 (in this order) such that the result is always 100. For example: 1 + 2 + 34 – 5 + 67 – 8 + 9 = 100.
-- Source: https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour
data Join = Plus | Minus | Concat deriving Show
compute :: Integer -> (Integer, Join) -> Integer
compute x (y, Plus) = x+y
compute x (y, Minus) = x-y
compute x (y, Concat) = read(show(x)++show(y))
@jan-swiecki
jan-swiecki / problem4.hs
Last active August 29, 2015 14:20
Problem4
-- Write a function that given a list of non negative integers,
-- arranges them such that they form the largest possible number.
-- For example, given [50, 2, 1, 9], the largest formed number is 95021.
-- Source: https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour
import Data.List
intCombinations :: [Int] -> [Int]
intCombinations xs = map (read.concat.(map show)) (permutations xs)
-- usage: solve [50, 2, 1, 9]
@jan-swiecki
jan-swiecki / docker-machine-install-docker-compose.sh
Created March 11, 2016 12:48
Installs docker-compose inside docker-machine
#!/bin/sh
# Installs docker-compose inside docker-machine
DOCKER_COMPOSE_VERSION=1.6.0
# Download docker-compose to the permanent storage
echo 'Downloading docker-compose to the permanent VM storage...'
sudo mkdir -p /var/lib/boot2docker/bin
sudo curl -sL https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` -o /var/lib/boot2docker/bin/docker-compose
@jan-swiecki
jan-swiecki / passphrase_gen.bash
Last active October 10, 2017 14:43
Passphrase generator for linux based on /dev/urandom and dict words available in linux
#!/bin/bash
# Usage: ./passphrase_gen.bash 4 > x && vim x
# We redirect to file and print via vim so no history is saved anywhere.
# Repeat after you get passphrase you like. Memorize it/write it down
# and remove x afterwards.
set -eo pipefail
words=/usr/share/dict/words
# https://serverfault.com/a/214620/216850
@jan-swiecki
jan-swiecki / keybase.md
Last active June 25, 2019 22:38
Adding keybase.io proof

Keybase proof

I hereby claim:

  • I am jan-swiecki on github.
  • I am janswiecki (https://keybase.io/janswiecki) on keybase.
  • I have a public key ASAsoFvBg3zpFZUzzQtdve3ZO4eOCQjYDVfyfF2DyvJ3rAo

To claim this, I am signing this object: