Skip to content

Instantly share code, notes, and snippets.

@timw4mail
timw4mail / GetSet.php
Created April 16, 2014 19:51
Trait for naive getter/setter methods
<?php
/**
* Trait to get rid of naive getter/setter boilerplate
*/
trait GetSet
{
/**
* Dynamically create getters/setters
@timw4mail
timw4mail / .zshrc
Created October 29, 2014 20:02
zsh config
# correction
setopt correctall
#prompt
autoload -U promptinit
promptinit
prompt clint
@timw4mail
timw4mail / ex16-extra-credit.c
Created February 4, 2015 21:34
Learn C the hard way
#include <stdio.h>
typedef struct {
char *name;
int age;
int height;
int weight;
} Person;
Person Person_create(char *name, int age, int height, int weight)
<IfModule mod_rewrite.c>
RewriteEngine On
# !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
# slashes.
# If your page resides at
# http://www.example.com/mypage/test1
# then use
# RewriteBase /mypage/test1/
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
@timw4mail
timw4mail / README
Created May 19, 2011 20:53
CSV Generating Class
A simple class for exporting data from a database into a CSV file.
If you want to directly output the CSV, simply call
CSV::export($field_names, $data, $filename);
Where:
$field_names is an array, either associative, with the keys of the array being the column headers, or a traditional array, with the values of the array being the column headers of the csv in the order you want them.
$data is either an array or object of arrays or objects containing your data in the same order as in the $field_names array
@timw4mail
timw4mail / prime.html
Created October 18, 2011 17:54
Javascript prime number generator
<!DOCTYPE html>
<html>
<head>
<title>JS Prime Generator</title>
</head>
<body>
<div id="res"></div>
<button id="generate">Generate more primes!</button>
<script type="text/javascript">
(function(){
@timw4mail
timw4mail / prime.php
Created October 19, 2011 14:55
PHP prime number generator
<!DOCTYPE html>
<html>
<head>
<title>Prime Number Generator</title>
</head>
<body onload="location.href='#bottom'">
<?php
$start = microtime(TRUE);
@timw4mail
timw4mail / kana.js
Created October 20, 2011 19:15
Javascript Kana transliterator
document.getElementById('sub').addEventListener('click', transliterate, false);
function transliterate()
{
var input = document.getElementById('in').value;
var action = document.getElementById('action').value;
var output;
switch(action)
{
@timw4mail
timw4mail / curl.php
Created October 26, 2011 00:53
Simple Curl function for retrieving a remote url
<?php
function do_curl($url, $options=array())
{
$cookie = tempnam ("/tmp", "CURLCOOKIE");
$ch = curl_init($url);
//Use the user's User Agent and Cookies
$opts= array(
CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
CURLOPT_COOKIEJAR => $cookie,
@timw4mail
timw4mail / README.md
Created January 12, 2012 19:35
PHP __toString() method for debugging

Use

In object: $this->__toString(); OR echo $this;

In object, var_dump: $this->__toString('var_dump');

Print out a different object: $class-&gt;__toString('print_r', $object);