Skip to content

Instantly share code, notes, and snippets.

View YoniTsafir's full-sized avatar

Yoni Tsafir YoniTsafir

View GitHub Profile
#include <iostream>
using namespace std;
void main()
{
int a = 1, b = 2;
int arr[] = {1, 3, 5, a, b};
int *p = arr + 1;
int **q = &p;
int ***crazy = new int**[*(arr + 4)];
@YoniTsafir
YoniTsafir / DelayedAssert.java
Created April 3, 2011 19:21
Code Sheriff's Code Examples
public interface ConditionTester {
boolean isTrue();
}
public static void delayedAssert(ConditionTester tester,
long timeout,
long pollingInterval)
throws InterruptedException {
long startTime = System.currentTimeMillis();
'''
Created on Apr 14, 2011
'''
class LCDCalculator(object):
def calc(self, num1, num2):
return reduce(lambda x, y: x * y, self.smart_union(self.factorize(num1), self.factorize(num2)))
def factorize(self, num):
@YoniTsafir
YoniTsafir / gist:1104645
Created July 25, 2011 17:27
mock 0.8 beta1 bug
# Old version:
>>> from mock import MagicMock
>>> a = MagicMock()
>>> a.foo("hello")
<mock.MagicMock object at 0xa40cecc>
>>> a.foo("goodbye")
<mock.MagicMock object at 0xa40cecc>
>>> a.foo.call_args_list
[(('hello',), {}), (('goodbye',), {})]
>>> a.foo.call_args_list[0]
@YoniTsafir
YoniTsafir / MyTest.h
Created December 11, 2011 14:59
Negative value SPTween bug
#import <SenTestingKit/SenTestingKit.h>
@interface MyTest : SenTestCase
@end
@YoniTsafir
YoniTsafir / sort.py
Created January 30, 2012 17:10
Code from TDD Workshop with Corey Haines
'''
Created on Jan 30, 2012
@author: yonits
'''
import unittest
def flip_indices(new_list, first_idx, second_idx):
@YoniTsafir
YoniTsafir / Q1.java
Created June 16, 2012 10:18
Does it compile? questions in java
public abstract class A {
private int x = 7;
public A(int x) {
this.x = x;
System.out.println("A::A, x=" + x);
}
public int getX() {
@YoniTsafir
YoniTsafir / Q11.java
Created June 18, 2012 20:57
Does it compile? questions in java II
class A {
private int x;
public A() {
this(7);
}
public A(int x) {
setX(x);
}
@YoniTsafir
YoniTsafir / Q19.java
Created June 23, 2012 08:08
Does it compile? questions in Java III
public class Main {
public static void main(String[] args) {
doSomething(7);
}
private static void doSomething(int num) throws Exception {
if (num > 10) {
throw new Exception("abcd");
} else {
System.out.println(num);
@YoniTsafir
YoniTsafir / open_leaan.sh
Created November 6, 2012 17:55
A way to obtain a session to leaan.co.il when there's a derby sale :)
#!/bin/bash
while [ 1 == 1 ]; do
curl http://www.leaan.co.il | grep Lean-Logo.png 2>&1 > /dev/null
if [ $? == 0 ]; then
open http://www.leaan.co.il;
fi
sleep 1
done