Skip to content

Instantly share code, notes, and snippets.

View cfilipov's full-sized avatar
💭
Yak shaving

Cristian Filipov cfilipov

💭
Yak shaving
View GitHub Profile
@cfilipov
cfilipov / client.ts
Last active January 25, 2023 23:02
dexie-dsync: a dexie addon for distributed sync using file storage like dropbox or google drive.
import { toVersion, Ordering } from 'version-vector';
import { mergeJoin, stringComparator, innerJoin, maybe, assert } from 'rr/util';
export interface Versioned {
version: string;
}
export interface Version extends Versioned {
readonly uid: string;
readonly band: string;
@cfilipov
cfilipov / bits.c
Created November 6, 2017 04:14
Bit fiddling in C
#include "stdio.h"
#include "stdint.h"
/**
* Print the binary representation of an integer `n` with length `len`.
* Any unsigned integer can be safely cast to uintmax_t.
*
* Shift right then mask to the last bit.
*/
void printb2(uintmax_t n, size_t len)
from bs4 import BeautifulSoup
import urllib2
def crawl(url):
html = urllib2.urlopen(url).read()
soup = BeautifulSoup(html)
rows = soup.findAll("table")[3].findAll("tr")
for row in rows[1:]:
cols = row.findAll("td")
ahref = cols[2].findAll("a")[0]
@cfilipov
cfilipov / MuscleBookCLA.md
Created October 18, 2016 16:38
Muscle Book Contributor License Agreement (CLA)

Copyright Assignment Agreement for Open Source Project: Cristian Filipov

You agree, understand, and state that:

  1. The term "Assigned Contributions" means the all contributions made to the specified Open Source project, in the case of computer code, automatically include the code in both binary and source forms, and any documentation and other files that accompany the code.

  2. You have received good and valuable consideration, and you agree to assign and do assign to Cristian Filipov your ownership of copyright in the Assigned Contributions, for the full duration thereof, and for any renewals or extensions thereof. To any extent that this assignment is ineffective, you grant to Cristian Filipov a nonexclusive, royalty-free, no-charge, worldwide, irrevocable and perpetual right to use, modify, and distribute the Assigned Contributions as it wishes.

  3. You will execute any documents and perform any acts Cristian Filipov requests to implement the letter and spirit of this agreement, except that you are not

@cfilipov
cfilipov / Undefined.swift
Created August 25, 2016 03:22
Undefined Func in Swift
///
/// From: https://realm.io/news/swift-summit-johannes-weiss-the-type-system-is-your-friend/
///
/// Slightly improved:
/// * Report function, file and line of actual call site
/// * Warn usage of this function (somewhat hacky though)
/// * Discardable result
@available(*, deprecated, message: "Use of undefined()")
@discardableResult public func undefined<T>(
_ message: StaticString = ""
@cfilipov
cfilipov / GRDB Create SQL Builder.swift
Created July 2, 2016 03:05
A Swift DSL for building SQLite table creation statements intended for GRDB
struct _CreateTableBuilder {}
struct _PrimaryKeyBuilder {}
struct _ForeignKeyBuilder {}
struct _SQLExpressible {}
struct _SQLSelectable {}
struct _CreateTableSelectBuilder {}
struct SQLColumn {
var name: String
@cfilipov
cfilipov / SwiftGenericTrie.md
Last active July 21, 2016 00:49
Generic-Key Trie in Swift

Generic Trie in Swift

This is an attempt to implement a trie in Swift with a generic key. Instead of using just strings as keys, this trie can be keyed by any object that can generate its own prefixes. This is accomplished by using a protocol to define a trie key that can return a generator of Hashables. We need Hashables because the prefixes will be stored in a Dictionary.

Defining the Key Type

The TrieNode class will be a private implementation detail. It helps to separate the implementation into TrieNode and the wrapper for a few reasons:

  1. If we want to extend the trie to implement some common Swift collection protocols, many of those don't make sense for every node.
  2. We want references for nodes but the wrapper struct can help us simulate value semantics.
// In the previous version https://gist.github.com/cfilipov/c9929dcb2cffcbf52a22, LocalFeed could only contain one type of Feed, this one allows it to store any feed type.
import Cocoa
protocol Feed: Equatable {
var url: String {get}
}
func ==<F: Feed>(lhs: F, rhs: F) -> Bool {
return lhs.url == rhs.url
//: Playground - noun: a place where people can play
import Cocoa
protocol Feed: Equatable {
var url: String {get}
}
func ==<F: Feed>(lhs: F, rhs: F) -> Bool {
return lhs.url == rhs.url
@cfilipov
cfilipov / StringsAndUnicode.swift
Created December 2, 2015 21:36
Strings & Unicode in Swift
/*:
# Strings and Unicode
*/
import Foundation
/*: Some things we can't do */
//let ❤ = "❤" // error: Expected a pattern
//let ☆ = "☆" // error: Expected a pattern