---
layout: post
title: "How to write proper PHP"
permalink: 2013/12/17/how-to-write-proper-php
postday: 2013/12/17
posttime: 05_57
tags: untagged
---
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 function adds 3 to the number passed in | |
function addThree(x) { | |
return x + 3; | |
} | |
//this function takes a function and returns | |
//a function that runs the function it was passed, | |
//and then runs that function _again_ on the return | |
//value of the first call to the function. | |
//make sense? look at it until it does. |
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
function addThree(x) | |
{ | |
return x + 3; | |
} | |
// Method one. | |
original = 4; | |
y = addThree(original); // 4 + 3 = 7 | |
z = addThree(y); // 7 + 3 = 10 |
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 | |
function return_false() | |
{ | |
return false; | |
} | |
function return_true() | |
{ | |
return true; |
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 | |
if (!defined("WHMCS")) | |
die("This file cannot be accessed directly"); | |
/* | |
************************************************ | |
*** FraudRecord Addon Module FOR WHMCS 5.x *** | |
*** Module Version 0.6.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
# I needed this for my nzbspider project (https://github.com/joepie91/nzbspider). Decided to throw up a stand-alone version. | |
import requests, socket | |
# Very nasty monkeypatching ahead! | |
socket.real_create_connection = socket.create_connection | |
class ModifiedSession(requests.Session): | |
def __init__(self, *args, **kwargs): | |
try: |
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
#!/usr/bin/env python2 | |
import socket, yaml, random, time | |
import cPickle as pickle | |
ctx = zmq.Context() | |
with open("config.yaml", "r") as cfile: | |
config = yaml.safe_load(cfile) |
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
import requests, time | |
sess = requests.Session() | |
sess.headers.update({"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36"}) | |
base_uri = "http://lowendtalk.com" | |
# First page | |
json = sess.get("%s/discussions.json" % base_uri).json() |
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
import requests, time | |
sess = requests.Session() | |
sess.headers.update({"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1650.63 Safari/537.36"}) | |
base_uri = "http://lowendtalk.com" | |
# First page | |
json = sess.get("%s/categories/offers.json" % base_uri).json() |
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
#!/usr/bin/env python2 | |
import zmq, zmqtimer, sys, socket | |
ctx = zmq.Context() | |
poller = zmq.Poller() | |
def sample(): | |
print "I am a sample function that runs every five and a half seconds!" |
OlderNewer