This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Using a loop: | |
def f(n): | |
if n == 1 or n == 0 : return n | |
else: | |
x = 0 | |
y = 1 | |
r = 0 | |
for i in range(n - 1): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#using list functions | |
def sort(a): | |
i = 1 | |
while(i < len(a)): | |
if i < 1: i = i + 1 | |
else: | |
p = i - 1 | |
if a[i] < a[p]: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This method is here so the class can be called statically per FuelPHP standards, without dramatically changing the approach for the entire library. This is to make support (since this is a multi-framework payments package) and documentation easier. | |
*/ | |
public static function __callStatic($method, $params) | |
{ | |
$method = $method; | |
$gateway = $params[0]; | |
$params = $params[1]; | |
$payments = new self(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abstract class Fuel_Payments | |
{ | |
//Array for storing class instances | |
private static $instances = array(); | |
/** | |
* Create a new instance | |
**/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This technique was invented by Kai Jaeger (http://kaijaeger.com/articles/the-singleton-design-pattern-in-javascript.html), I'm just showing an implementation | |
var Singleton = (function() | |
{ | |
var instance = false; | |
/* | |
* Because this is in a closure, it cannot be accessed | |
*/ | |
var member = 'test'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int printSomething() | |
{ | |
printf("%s", "Something"); | |
return 1; | |
} | |
int main() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdio.h" | |
int main() | |
{ | |
int x = 1, y = 2, z = 3; | |
if(y > z ^ x > y ^ x > 0) printf("%s \n \n", "True!"); //Only one condition is true, statement evaluates to boolean true | |
if(z > y ^ x > 0) printf("%s \n \n", "Also True!"); //Both conditions are true. Statement evaluates to boolean false and "Also True!" is not printed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdio.h" | |
int main() | |
{ | |
int x, z, y = 2, a = 3, r; | |
x = y << 2; //Binary operation. Bits are shifted two places to the left (001 becomes 100). This evalutes to 8 | |
printf("%d \n \n", x); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdio.h" | |
int main() | |
{ | |
char c = 'a'; | |
int d, e; | |
d = c - 'a'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Dependency injection can help you reduce coupling and increase testability, making your applications more maintainable. | |
* | |
* DependencyResolver gives you the best of both worlds by mixing a registry with call time dependency resolution. In addition, it provides significant resource | |
* usage advantages over other patterns, such as an object pool, because dependencies are only resolved when they are actually needed. | |
* | |
* It supports both constructor injection for class wide dependencies, as well as method injection for method specific dependencies. | |
* |
OlderNewer