Skip to content

Instantly share code, notes, and snippets.

View kssreeram's full-sized avatar

KS Sreeram kssreeram

View GitHub Profile
@kssreeram
kssreeram / parse.py
Created July 8, 2015 14:08
Writing Parsers
import sys
#
# ParserInput
#
# This class represents the input data and the current
# position in the data.
#
# Brief note about 'max_position':
@kssreeram
kssreeram / deep_merge_with.py
Created July 22, 2015 14:36
Python version of Clojure's merge-with and deep-merge-with
import operator
import itertools
def merge_key_with(f, k, dicts) :
if all((k in d) for d in dicts) :
return f(*(d[k] for d in dicts))
else :
first = next(itertools.ifilter(lambda d : k in d, dicts))
return first[k]
@kssreeram
kssreeram / infix-to-postfix.py
Last active August 29, 2015 14:26
Infix to Postfix
#
# Program to convert infix expressions to postfix.
# It supports the following operators:
# - Addition ("+")
# - Multiplication ("*")
# - Logarithm ("L")
#
# Single digit values are supported.
# Lower-case alphabets are considered as variables.
#
@kssreeram
kssreeram / gist:0283ec0804cd5c7354a0c25a630708ac
Created April 19, 2016 09:02
Swift compiler stack trace
^\0 swift 0x000000010744f4eb llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 43
1 swift 0x000000010744e7d6 llvm::sys::RunSignalHandlers() + 70
2 swift 0x000000010744fb4f SignalHandler(int) + 287
3 libsystem_platform.dylib 0x00007fff8cfc152a _sigtramp + 26
4 libsystem_platform.dylib 000000000000000000 _sigtramp + 1929636592
5 swift 0x00000001052bc95c swift::irgen::SingleScalarTypeInfo<(anonymous namespace)::PrimitiveTypeInfo, swift::irgen::LoadableTypeInfo>::unpackFromEnumPayload(swift::irgen::IRGenFunction&, swift::irgen::EnumPayload const&, swift::irgen::Explosion&, unsigned int) const + 28
6 swift 0x00000001052af4f9 swift::irgen::RecordTypeInfo<(anonymous namespace)::LoadableStructTypeInfo, swift::irgen::LoadableTypeInfo, (anonymous namespace)::StructFieldInfo, true>::unpackFromEnumPayload(swift::irgen::IRGenFunction&, swift::irgen::EnumPayload const&, swift::irgen::Explosion&, unsigned int) const + 89
7
@kssreeram
kssreeram / nested-structs.swift
Created April 19, 2016 10:48
Crash swift with nested structs.
//
// Helpers
//
import Foundation;
func bytesToNSData(a:[UInt8]) -> NSData {
return NSData(bytes:a, length:a.count);
}
@kssreeram
kssreeram / arc-test.swift
Created June 23, 2016 03:09
Swift ARC Problem
class A {
var values:[Int] = [];
}
func append1(inout a:A) {
let n = a.values.count;
a.values.append(n);
}
func append2(inout a:A) {
@kssreeram
kssreeram / inout-crash.swift
Created June 23, 2016 04:51
Swift "inout" crasher
func testAlias(inout a:(Int, Int), inout _ b:Int) {
print((a, b));
}
var v = (10, 20);
testAlias(&v, &v.0);
@kssreeram
kssreeram / inout-test.swift
Created June 23, 2016 09:37
Guess the output...
func test1(inout v:[Int], inout _ x:Int) {
v[0] += 1;
x += 1;
}
func test2(inout v:[Int], inout _ x:Int) {
v[0] += 1;
v.append(20);
x += 1;
}
@kssreeram
kssreeram / c-ambiguity.txt
Created June 28, 2016 07:27
Handling C ambiguity
Modeling C Ambiguity.
@kssreeram
kssreeram / test-bug.c
Created June 16, 2018 21:33
Bug in Clang
/*
This program triggers a bug in Clang when compiling with optimizations.
When compiling with no-optimizations, the correct output is produced.
$ clang -O0 test-bug.c && ./a.out
value = 1