Skip to content

Instantly share code, notes, and snippets.

View SerpentChris's full-sized avatar

Chris Calderon SerpentChris

  • Sunnyvale
View GitHub Profile
@SerpentChris
SerpentChris / why.py
Created June 5, 2018 14:50
terse versions of reduce and defaultdict with no imports
_r = lambda func, lst, first: _r(func, lst[1:], func(first, lst[0])) if lst else first
reduce = lambda func, lst, first=None: _r(func, lst[1:], lst[0]) if first is None else _r(func, lst, first)
_init = lambda self, typ: setattr(self, 'factory', typ)
_get = lambda self, key: dict.__getitem__(self, key) if key in self else dict.__setitem__(self, key, self.factory()) or dict.__getitem__(self, key)
defaultdict = type('defaultdict', (dict,), {'__init__': _init, '__getitem__': _get})
@SerpentChris
SerpentChris / download_latin_phrases.py
Last active April 17, 2018 02:53
Downloads Latin phrases from Wikipedia's Latin phrases appendix.
## Copyright (c) 2018 Christian Calderon
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included in all
@SerpentChris
SerpentChris / truth_tables.py
Last active February 3, 2018 01:17
A small program that generates truth tables from arguments in sentential logic.
#!/usr/bin/env python3
#
# Copyright (c) 2018 Christian Calderon
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@SerpentChris
SerpentChris / hodl2.sol
Last active January 2, 2018 19:02
HODL your tokens AND your ETH!
pragma solidity ^0.4.19;
// Copyright (c) 2017 Christian Calderon
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@SerpentChris
SerpentChris / hodl.sol
Last active December 31, 2017 15:53
A smart contract that helps people HODL
pragma solidity ^0.4.19;
// Copyright (c) 2017 Christian Calderon
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@SerpentChris
SerpentChris / sol_tester.py
Last active September 28, 2017 21:12
Using ethereum.tester with Solidity
# Copyright (c) 2017 Christian Calderon
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
@SerpentChris
SerpentChris / partitions.py
Last active September 15, 2017 19:19
Calculates the partition function with Python
# Copyright (c) 2017 Christian Calderon
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
@SerpentChris
SerpentChris / mybrowser.py
Last active September 15, 2017 19:19
A shitty web browser
#!/usr/bin/env python3
# Copyright (c) 2017 Christian Calderon
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
@SerpentChris
SerpentChris / sha256.py
Last active November 12, 2022 23:00
SHA256 written in pure Python3
# Copyright (c) 2017, 2022 Christian Calderon
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
@SerpentChris
SerpentChris / linkedList.js
Last active May 18, 2017 18:19
A LISP inspired linked list in Javascript
const nil = {}
function isNil(p){
return p === nil
}
function makePair(a, b){
return {head: a, tail: b}
}