Skip to content

Instantly share code, notes, and snippets.

@hsavit1
hsavit1 / Server_simple.swift
Created December 7, 2015 17:47
Simple Server in Swift
/* Creates a server that is bound to a socket to listen for incoming
connections. Also creates a client which sends a "Hello world"
message to server. Shows how servers can be made in Swift.
*/
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
import Darwin
#else
import Glibc
#endif
@hsavit1
hsavit1 / transducer-type.swift
Created December 12, 2015 06:31 — forked from mbrandonw/transducer-type.swift
How to get a transducer type without higher kinds
import Foundation
// A bunch of convenience things
func const <A, B> (b: B) -> A -> B {
return { _ in b }
}
func repeat <A> (n: Int) -> A -> [A] {
return { a in
return map(Array(1...n), const(a))
}
import { buildSchema, graphql } from "graphql";
// Construct a schema, using GraphQL schema language
let graphqlSchema = buildSchema(`
type Query {
recipes: [Recipe]
recipes_by_pk(id: Int!): Recipe
}
type Recipe {
id: ID!
@hsavit1
hsavit1 / sql_parser.exs
Created June 5, 2020 01:57 — forked from sasa1977/sql_parser.exs
Basic SQL parser developed at WebCamp Zagreb, 2019
defmodule SqlParser do
def run() do
input = "select col1 from (
select col2, col3 from (
select col4, col5, col6 from some_table
)
)
"
IO.puts("input: #{inspect(input)}\n")
IO.inspect(parse(input))

Keybase proof

I hereby claim:

  • I am hsavit1 on github.
  • I am henry_s (https://keybase.io/henry_s) on keybase.
  • I have a public key ASBehtOERO0XSzcL87y6jBqgpvrxRE2XOHqBxl2LZc4Z5Qo

To claim this, I am signing this object:

@hsavit1
hsavit1 / RAC_Gesture.m
Created July 25, 2015 04:14
RAC demonstration of a pan gesture
@interface RACGestureViewController ()
@property(weak, nonatomic) IBOutlet UILabel *translationLabel;
@property(weak, nonatomic) IBOutlet UILabel *stateLabel;
@property(strong, nonatomic) RACSubject *animationDelegate;
@property(weak, nonatomic) IBOutlet UILabel *pinchLabel;
@end
@implementation RACGestureViewController
@hsavit1
hsavit1 / RAC_Samples.m
Created July 21, 2015 00:53
101 RAC Sample
//
// main.m
// 101RACSamples
//
// Created by Matthew Doig on 1/26/14.
// Copyright (c) 2014 DWI. All rights reserved.
//
#pragma mark Asynchronous operators
@hsavit1
hsavit1 / Generator.swift
Created December 1, 2015 07:35
Using generators with tableviews in swift
protocol AsyncGeneratorType {
typealias Element
typealias Fetch
mutating func next(fetchNextBatch: Fetch, onFinish: ((Element) -> Void)?)
}
/// Generator is the class because struct is captured in asynchronous operations so offset won't update.
class PagingGenerator<T>: AsyncGeneratorType {
typealias Element = Array<T>
typealias Fetch = (offset: Int, limit: Int, completion: (result: Element) -> Void) -> Void
@hsavit1
hsavit1 / Example.m
Last active April 5, 2018 14:25
Multicast Delegate Pattern in Objective C to add multiple delegates to something
#import "UITextViewHideKeyboardOnEnterBehaviour.h"
#import "UITextView+Multicast.h"
@implementation UITextViewHideKeyboardOnEnterBehaviour
- (id)initWithTextView:(UITextView *)textView
{
if (self=[super init])
{
[textView.multicastDelegate addDelegate:self];
@hsavit1
hsavit1 / tco.py
Created December 19, 2015 17:44
Tail Call Optimized Python Decorator
class TailPromise(object):
__metaclass__ = PromiseMetaClass
def __init__(self,func,args,kw):
self.__func = func
self.__args = args
self.__kw = kw
def __arginfo__(self):
return self.__args, self.__kw