Skip to content

Instantly share code, notes, and snippets.

View MilkZoft's full-sized avatar

Carlos Santana Roldán MilkZoft

View GitHub Profile
@MilkZoft
MilkZoft / cut.php
Created January 20, 2012 03:51
codejobs - Cut words - PHP
<?php
function cut($text, $length = 12, $type = "text", $file = FALSE, $elipsis = FALSE) {
if($type === "text") {
$elipsis = "...";
$words = explode(" ", $text);
if(count($words) > $length) {
return str_replace("\n", "", implode(" ", array_slice($words, 0, $length)) . $elipsis);
}
@MilkZoft
MilkZoft / singularize.php
Created January 19, 2012 03:30
codejobs - Singularize words
<?php
function singularize($word) {
$uncountable = array("sheep",
"fish",
"deer",
"series",
"species",
"money",
"rice",
"information",
@MilkZoft
MilkZoft / pluralize.php
Created January 19, 2012 03:19
codejobs - Pluralize Words - PHP
<?php
function pluralize($word) {
$uncountable = array("sheep",
"fish",
"deer",
"series",
"species",
"money",
"rice",
"information",
@MilkZoft
MilkZoft / zip.php
Created January 19, 2012 03:12
codejobs - Create a Zip file - PHP
<?php
function createZip($files = array(), $destination = NULL, $overwrite = FALSE) {
if(file_exists($destination) and !$overwrite) {
return FALSE;
}
$validFiles = array();
if(is_array($files)) {
foreach($files as $file) {
@MilkZoft
MilkZoft / code.php
Created January 19, 2012 03:09
codejobs - Generates a random code (Hash) - PHP
<?php
function code($max = 10, $uppercase = TRUE) {
return ($uppercase) ? strtoupper(substr(md5(date("Y-m-d H:i:s", time())), 0, $max)) : substr(md5(date("Y-m-d H:i:s", time())), 0, $max);
}
?>
@MilkZoft
MilkZoft / ping.php
Created January 19, 2012 03:06
codejobs - Ping - PHP
<?php
function ping($domain) {
$domain = str_replace("http://", "", $domain);
if(!@file_get_contents("http://" . $domain)) {
return FALSE;
} else {
return TRUE;
}
}
@MilkZoft
MilkZoft / ip.php
Created January 19, 2012 03:04
codejobs - Get IP - PHP
<?php
function getIP() {
if(isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
if(isset($_SERVER["HTTP_CLIENT_IP"])) {
return $_SERVER["HTTP_CLIENT_IP"];
} else {
return $_SERVER["REMOTE_ADDR"];
}
return $_SERVER["HTTP_X_FORWARDED_FOR"];
@MilkZoft
MilkZoft / image.m
Created January 18, 2012 22:01
codejobs - Correct way to draw background using a pattern image - Objective-C
// Save the current graphics state first so we can restore it.
[[NSGraphicsContext currentContext] saveGraphicsState];
// Change the pattern phase.
[[NSGraphicsContext currentContext] setPatternPhase:
NSMakePoint(0,[self frame].size.height)];
// Stick the image in a color and fill the view with that color.
NSImage *anImage = [NSImage imageNamed:@"bricks"];
[[NSColor colorWithPatternImage:anImage] set];
@MilkZoft
MilkZoft / filter.php
Created January 18, 2012 04:30
codejobs - Filter profanity - PHP
<?php
function isVulgar($string, $max = 1) {
$words = array(
"puto", "puta", "perra", "tonto", "tonta", "pene", "pito", "chinga", "tu madre", "hijo de puta", "verga", "pendejo", "baboso",
"estupido", "idiota", "joto", "gay", "maricon", "marica", "chingar", "jodete", "pinche", "panocha", "vagina", "zorra", "fuck",
"chingada", "cojer", "imbecil", "pendeja", "piruja", "puerca", "polla", "capullo", "gilipollas", "cabron", "cagada", "cago", "cagar",
"mierda", "marrano", "porno", "conche", "tu puta madre", "putas", "putos", "pendejas", "pendejos", "pendejadas", "mamadas", "lesbianas",
"coño", "huevon", "sudaca", "fucker", "ramera"
);
@MilkZoft
MilkZoft / spam.php
Created January 18, 2012 04:25
codejobs - Filter SPAM words - PHP
<?php
function isSPAM($string, $max = 2) {
$words = array(
"http", "www", ".com", ".mx", ".org", ".net", ".co.uk", ".jp", ".ch", ".info", ".me", ".mobi", ".us", ".biz", ".ca", ".ws", ".ag",
".com.co", ".net.co", ".com.ag", ".net.ag", ".it", ".fr", ".tv", ".am", ".asia", ".at", ".be", ".cc", ".de", ".es", ".com.es", ".eu",
".fm", ".in", ".tk", ".com.mx", ".nl", ".nu", ".tw", ".vg", "sex", "porn", "fuck", "buy", "free", "dating", "viagra", "money", "dollars",
"payment", "website", "games", "toys", "poker", "cheap"
);
$count = 0;