Skip to content

Instantly share code, notes, and snippets.

//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.
function addThree(x)
{
return x + 3;
}
// Method one.
original = 4;
y = addThree(original); // 4 + 3 = 7
z = addThree(y); // 7 + 3 = 10
@joepie91
joepie91 / gist:3118866
Created July 15, 2012 22:05
Testing variable assignments within if statements in PHP
<?php
function return_false()
{
return false;
}
function return_true()
{
return true;
<?php
if (!defined("WHMCS"))
die("This file cannot be accessed directly");
/*
************************************************
*** FraudRecord Addon Module FOR WHMCS 5.x ***
*** Module Version 0.6.1
@joepie91
joepie91 / ip-binding-monkeypatch.py
Last active December 19, 2015 04:19
READ ALL OF THIS, IT'S IMPORTANT: This is how you monkeypatch support for binding to a specific IP into Python Requests. You use the new bound_ip keyword argument when creating a new session, to assign a certain IP to that Requests session. All subsequent HTTP requests made from that session via the standard methods, will be bound to that IP. No…
# 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:
@joepie91
joepie91 / bot.py
Created December 8, 2013 14:06
Basic IRC bot
#!/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)
@joepie91
joepie91 / let-sink.py
Created December 17, 2013 04:42
All sunk threads on LowEndTalk
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()
@joepie91
joepie91 / let-sink-offers.py
Created December 17, 2013 06:37
Sunken-ness of threads in the Offers category on LowEndTalk...
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()
@joepie91
joepie91 / usage.py
Created January 24, 2014 13:15
ZeroMQ Timer (for poller loop)
#!/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!"
---
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
---