Skip to content

Instantly share code, notes, and snippets.

@adrienbrault
adrienbrault / gist:956984
Created May 5, 2011 12:59
Java fizzbuzz
public class MyFirstProgram {
public static void main(String args[]) {
for(int i = 1; i <= 100; i++) {
boolean mod3 = i % 3 == 0;
boolean mod5 = i % 5 == 0;
boolean lineBreak = (i - 9) % 10 == 0;
<?php
use Symfony\Component\ClassLoader\UniversalClassLoader;
$loader = new UniversalClassLoader();
$loader->registerNamespaces(array(
'Symfony' => array(__DIR__.'/../vendor/symfony/src', __DIR__.'/../vendor/bundles'),
'Sensio' => __DIR__.'/../vendor/bundles',
'JMS' => __DIR__.'/../vendor/bundles',
'Doctrine\\Common' => __DIR__.'/../vendor/doctrine-common/lib',
NSView *myView = ...;
myView.wantsLayer = YES; // The thing you must not forget.
CGPoint newPosition = CGPointMake(100.0, 200.0);
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
animation.fromValue = [NSValue valueWithPoint:myView.frame.origin];
animation.toValue = [NSValue valueWithPoint:newPosition];
animation.duration = 1.0;
@interface UINavigationBar (CustomBackground)
- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index;
@end
Graphics2D graphics2D = (Graphics2D)graphics;
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
@adrienbrault
adrienbrault / gist:1020447
Created June 11, 2011 10:42
Get the current position of an animated view with CoreAnimation
NSView *animatedView = ...;
CALayer *presentationLayer = (CALayer*)animatedView.layer.presentationLayer;
CGPoint currentPosition = presentationLayer.position;
@adrienbrault
adrienbrault / gist:1035812
Created June 20, 2011 15:19
How to count the number of lines in a source code
find dir -exec cat {} \; | wc -l
{
case 1:
callFirstFunction();
break;
case 2:
callFirstFunction();
break;
case 3:
- (void)drawRect:(NSRect)dirtyRect
{
NSGraphicsContext *graphicContext = [NSGraphicsContext currentContext];
CGContextRef context = [graphicContext graphicsPort];
// Set the origin of the coordinate system in the upper left corner instead of the lower left corner.
CGContextConcatCTM(context,
CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0, self.frame.size.height));
}
<?php
$entities = array(
new User(1, 'John'),
new User(2, 'Steve'),
);
$ids = array_map(function ($entity) {
return $entity->getId();
}, $entities);