Skip to content

Instantly share code, notes, and snippets.

View marcinczenko's full-sized avatar
💭
https://idbox.online

Marcin Czenko marcinczenko

💭
https://idbox.online
View GitHub Profile
@marcinczenko
marcinczenko / bencoder.py
Last active May 21, 2025 16:37
A simple script to bencode BitTorrent info dictionary (v1, single file)
import itertools as it
import os
import json
from hashlib import sha1
def to_hex(b):
return [block.hex() for block in b]
def encode(obj):
"""
@marcinczenko
marcinczenko / raisingfutures2.nim
Last active April 7, 2025 05:58
nim: working with checked exceptions
import std/sequtils
import std/macros
import pkg/chronos
from pkg/chronos/internal/raisesfutures import makeNoRaises
macro newRaisingFuture(T: typedesc, E: typed, fromProc: static[string] = ""): untyped =
let
baseType = T.strVal
e =
{.push raises: [].}
import pkg/chronos
type
MyError = object of CatchableError
Handle1 = Future[void].Raising([CancelledError])
Handle2 = Future[void].Raising([CancelledError, MyError])
SomeType = object
@marcinczenko
marcinczenko / example-webpackbar-next.config.js
Created April 21, 2021 12:27
NextJs: bundle compilation time in development
const WebpackBar = require('webpackbar')
module.exports = {
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
// Note: we provide webpack above so you should not `require` it
// Perform customizations to webpack config
config.plugins.push(new WebpackBar({
name: 'Bundle'
}))
@marcinczenko
marcinczenko / next.config.js
Created April 21, 2021 12:17
Example next.config.js to show bundle compilation time in development and bundle stats in production
const WebpackBar = require('webpackbar')
const withPlugins = require('next-compose-plugins')
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true'
})
const withMDX = require('@next/mdx')({
extension: /\.mdx?$/,
use: ['babel-loader', '@mdx-js/loader']
})
@marcinczenko
marcinczenko / Dockerfile
Created December 1, 2017 14:25
Dockerfile for Ubuntu based node.js 9.2.0 with npm, yarn and git.
FROM ubuntu:latest
RUN apt-get update; \
apt-get install -y curl; \
apt-get install -y apt-transport-https; \
(curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -); \
(echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list); \
apt-get update; \
(curl -sL https://deb.nodesource.com/setup_9.x | bash -); \
apt-get install -y nodejs; \

Keybase proof

I hereby claim:

  • I am marcinczenko on github.
  • I am marcinczenko (https://keybase.io/marcinczenko) on keybase.
  • I have a public key ASDqrBammzBkDZishBDP32HbZNrFDqhua6C1Ho_TfCym_Ao

To claim this, I am signing this object:

import Foundation
import CoreData
protocol EPQuantity {
associatedtype EPQuantityValueType
func getValue() -> EPQuantityValueType
}
struct EPAcceleration: EPQuantity, CustomStringConvertible {
let acceleration: Double
@marcinczenko
marcinczenko / AroundTypeErasureInSwift.playground
Created June 28, 2016 17:04
A Swift playground for the blog post "Around TypeErasure in Swift"
import Foundation
protocol Logger {
associatedtype LoggerItemType
func log(item: LoggerItemType)
}
struct AnyLogger<LoggerItemType> : Logger {
@marcinczenko
marcinczenko / SwiftStringConversion.playground
Last active February 11, 2016 11:47
Playground demonstrates how can you properly add String conversion to your own classes. See http://blog.redgreenrefactor.eu/post/139107029424/string-conversions-in-swift.
//: Playground - noun: a place where people can play
class MyClass: CustomStringConvertible {
let counter: Int
var description: String {
return "{ counter: \(self.counter) }"
}
init(withCounter: Int) {