Skip to content

Instantly share code, notes, and snippets.

View horror.js
// Version 1: Prints "1"
function foo() {
x = 1;
}
foo();
console.log(x);
//------------------------------------
@jkoppel
jkoppel / java_samples.java
Created Oct 16, 2016
Test cases from hell
View java_samples.java
/* Original samples:
Sample 7:
Query rangeQuery(String field, Object lowerTerm, Object upperTerm,
boolean includeLower, boolean includeUpper) {
double l = Double.NEGATIVE_INFINITY;
double u = Double.POSITIVE_INFINITY;
if (lowerTerm != null) {
l = parse(lowerTerm);
View minitest347.sk
pragma options "--bnd-inline-amnt 5 --bnd-inbits 2 --bnd-cbits 3 ";
int BASE = 4;
int[2*N] mult(int N, int[N] x, int[N] y){
int[2*N] out = 0;
for(int i=0; i<N; ++i){
for(int j=0; j<N; ++j){
View test_codecmaps_cn_trans_tac.py
from test import multibytecodec_support
import unittest
# Inlining t5 makes the test pass
t5 = multibytecodec_support.TestBase_Mapping
class TestGB18030Map(t5, unittest.TestCase):
encoding = 'gb18030'
mapfileurl = 'http://www.pythontest.net/unicode/gb-18030-2000.xml'
t7 = __name__ == "__main__"
View ilp.curry
data Exp = Lit String
pprint :: Exp -> String
pprint = (\(Lit s) -> a ++ "'" ++ s ++ "'") where a free
pprint = (\(Lit s) -> a ++ "\"" ++ s ++ "\"") where a free
parse :: String -> (Exp, Exp -> String)
parse s | s =:= f x = (x, f)
where
f = pprint
View adt_test.sk
adt Prog {
Var1 {}
Var2 {}
Const {int val; }
Add { Prog left; Prog right; }
Mul { Prog left; Prog right; }
}
int interpret(Prog prog, int x, int y) {
switch(prog) {
@jkoppel
jkoppel / jnettool.py
Created Sep 16, 2017
Example from Raymond Hettinger's talk, "Beyond PEP 8 -- Best practices for beautiful intelligible code - PyCon 2015"
View jnettool.py
# From "Raymond Hettinger - Beyond PEP 8 -- Best practices for beautiful intelligible code - PyCon 2015"
# Bad code
import jnettools.toolselements.NetworkElement, \
jnettools.tools.Routing, \
jnettools.tools.RouteInspector
ne=jnettools.tools.elements.NetworkElement( '171.0.2.45' )
try:
View ConstMemDlc.hs
{-# LANGUAGE GADTs, TypeOperators, DeriveFunctor, DataKinds, KindSignatures, MultiParamTypeClasses, FlexibleInstances, FlexibleContexts, OverlappingInstances, TypeFamilies, UndecidableInstances, FunctionalDependencies, ScopedTypeVariables #-}
module ConstMemDlc where
import qualified Data.Map as Map
import Data.Proxy
import GHC.TypeLits
import Data.Type.Equality
View HowAreEqualityConstraintsCompiled.hs
{-# LANGUAGE GADTs #-}
module HowAreEqualityConstraintsCompiled where
data TypeEq a b where
Refl :: (a ~ b) => TypeEq a b
@jkoppel
jkoppel / debug.cpp
Created Oct 9, 2017
Example of making debug output in Ironfist
View debug.cpp
extern int __fastcall InitMenuHandler_orig(struct tag_message & msg);
extern font* smallFont;
extern font* bigFont;
extern heroWindow* gpInitWin;
extern void __fastcall FillBitmapArea(class bitmap *, int, int, int, int, int);
int __fastcall InitMenuHandler(struct tag_message & msg) {
if (msg.eventCode == INPUT_MOUSEMOVE_EVENT_CODE) {