Skip to content

Instantly share code, notes, and snippets.

View marcin-chwedczuk's full-sized avatar

Marcin Chwedczuk marcin-chwedczuk

View GitHub Profile
@marcin-chwedczuk
marcin-chwedczuk / postman.desktop
Created May 3, 2018 14:17
Postman Ubuntu launcher
#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=/home/mc/bin/postman/Postman/Postman
Name=Postman
Comment=Postman
Icon=/home/mc/bin/postman/Postman/resources/app/assets/icon.png
@marcin-chwedczuk
marcin-chwedczuk / swap-tress.js
Created January 14, 2018 10:05
Swap trees.js
function places(treeHeights) {
var N = treeHeights.length;
var H = 0;
for (var i = 1; i < N - 1; i++) {
H += dH(i);
}
for (var firstTree = 0; firstTree < N; firstTree++) {
@marcin-chwedczuk
marcin-chwedczuk / Main.java
Created November 15, 2017 19:43
Modify JSON using FastXML Jackson without explicit deserialization
public static void main(String[] args) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
ObjectNode rootNode = (ObjectNode)
mapper.readTree(Main.class.getResource("toModify.json"));
ArrayNode listOfObjectsToModify =
(ArrayNode) rootNode.get("listOfObjectsToModify");
@marcin-chwedczuk
marcin-chwedczuk / compute_e.js
Created September 19, 2016 17:59
Compute 116 000 digits of e using Steve Wozniak algorithm from Byte
// see: https://archive.org/stream/byte-magazine-1981-06/1981_06_BYTE_06-06_Operating_Systems#page/n393/mode/2up
function word(x) { return (x & 0xffff); }
function wordstr(x) { return ('0000000000000000' + x.toString(16)).slice(-4); }
function divide(dividendWords, divisorWord, prevRest) {
var BITS_PER_WORD = 16;
var MAX_DIVISOR = (1 << 16) - 1;
@marcin-chwedczuk
marcin-chwedczuk / minimax.js
Created May 3, 2016 07:49
TicTacToe with minimax
#!/usr/bin/env node
// board is single array
// [x, x, x,
// x, x, x,
// x, x, x]
// where x may be string 'X', 'O', or null
var readline = require('readline-sync');
@marcin-chwedczuk
marcin-chwedczuk / scope_per_method_call_castle_windsor.cs
Created January 30, 2016 09:21
Scope per method call - custom scope
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Castle.Core;
using Castle.DynamicProxy;
using Castle.MicroKernel;
@marcin-chwedczuk
marcin-chwedczuk / foo.js
Created January 2, 2016 18:58
javascript quine 2
(function f() { console.log(['(',f.toString(),')()'].join('')); })()
@marcin-chwedczuk
marcin-chwedczuk / foo.cs
Created October 26, 2015 18:20
Simulating ?. operator in C# 5
using System;
public static class ObjectHelpers {
public static TResult WhenNotNull<T, TResult>(this T @object, Func<T,TResult> expression)
//where T: class
where TResult: class
{
if (@object == null)
return null;
@marcin-chwedczuk
marcin-chwedczuk / setup fake beacon
Created March 28, 2015 13:12
a bunch of hciXXX instruction to setup custom beacon
hciconfig hci0 reset
hciconfig hci0 -a
hciconfig hci0 noscan
sleep 1
hciconfig hci0 noleadv
sleep 1
@marcin-chwedczuk
marcin-chwedczuk / game_of_live.tsql
Created March 21, 2015 10:31
Game of live in T-SQL
use TSQL2012;
if exists (select * from sys.schemas where name = 'gol')
begin
drop function gol.global_variable;
drop procedure gol.print_board;
drop procedure gol.init_board;
drop procedure gol.iteration;
drop procedure gol.iterate;