Skip to content

Instantly share code, notes, and snippets.

Avatar

Marcin Chwedczuk marcin-chwedczuk

View GitHub Profile
View check-null-csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NullChecking {
struct NonNull<T>
where T : class
{
@marcin-chwedczuk
marcin-chwedczuk / Using scopes
Created Jul 30, 2014
Using scoped lifestyle windsor.castle
View Using scopes
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Castle.MicroKernel.Lifestyle;
namespace Castle_ScopeLifetime {
View gist:0586e8c946ae0ec5e185
var s="var s=\x22%\x22; console.log(s.replace(\x22%\x22,s.replace(new RegExp(String.fromCharCode(34),\x22g\x22),String.fromCharCode(92)+\x22x22\x22)))"; console.log(s.replace("%",s.replace(new RegExp(String.fromCharCode(34),"g"),String.fromCharCode(92)+"x22")))
View game_of_live.tsql
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;
@marcin-chwedczuk
marcin-chwedczuk / setup fake beacon
Created Mar 28, 2015
a bunch of hciXXX instruction to setup custom beacon
View setup fake beacon
hciconfig hci0 reset
hciconfig hci0 -a
hciconfig hci0 noscan
sleep 1
hciconfig hci0 noleadv
sleep 1
@marcin-chwedczuk
marcin-chwedczuk / foo.cs
Created Oct 26, 2015
Simulating ?. operator in C# 5
View foo.cs
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 / foo.js
Created Jan 2, 2016
javascript quine 2
View foo.js
(function f() { console.log(['(',f.toString(),')()'].join('')); })()
View scope_per_method_call_castle_windsor.cs
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 / minimax.js
Created May 3, 2016
TicTacToe with minimax
View minimax.js
#!/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 / btree.js
Created May 30, 2016
BTree implementation in JavaScript
View btree.js
#!/usr/bin/env node
const NKEYS = 4;
function arrayOfSize(size) {
var a = Array(size);
for (var i = 0; i < size; i += 1)
a[i] = null;