Skip to content

Instantly share code, notes, and snippets.

View plasticbrain's full-sized avatar

Mike Everhart plasticbrain

View GitHub Profile
@plasticbrain
plasticbrain / php-curl.php
Created September 11, 2012 01:10
PHP: Using cURL
<?php
// Initialize cURL
$ch = curl_init();
// The URL to load
curl_setopt($ch, CURLOPT_URL, 'http://www.url-to-load.com');
// Uncomment the following two lines to send POST data
// curl_setopt($ch,CURLOPT_POST, count($post_data_array));
@plasticbrain
plasticbrain / upload-and-parse-csv-file.php
Created September 11, 2012 23:02
PHP: Upload and parse CSV file
<form action="" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" name="btn_submit" value="Upload File" />
<?php
$fh = fopen($_FILES['file']['tmp_name'], 'r+');
$lines = array();
while( ($row = fgetcsv($fh, 8192)) !== FALSE ) {
$lines[] = $row;
@plasticbrain
plasticbrain / php-regex-patterns
Created September 11, 2012 23:26
PHP: (REGEX/preg_replace) replace multiple characters (ie: spaces)
//--------------------------------------------------------------------------
// Replace multiple spaces with a single space
// Substitute "\s\s" with whatever characters you want to check for
//--------------------------------------------------------------------------
$text = preg_replace("/\s\s+/", ' ', $text);
@plasticbrain
plasticbrain / Sublime Text Plugins
Created September 13, 2012 20:18
Sublime Text: Plugins
Package Manager
http://wbond.net/sublime_packages/package_control
SodaTheme
https://github.com/buymeasoda/soda-theme
CodeIgniter Snippets
https://github.com/mpmont/ci-snippets
jQeury Snippets
@plasticbrain
plasticbrain / gist:3717322
Created September 13, 2012 20:21
Sublime Text: User Keybindings
[
{ "keys": ["f1"], "command": "goto_documentation" }
]
@plasticbrain
plasticbrain / gist:3717327
Created September 13, 2012 20:22
Sublime Text: Default Keybindings (edited)
[
{ "keys": ["ctrl+q"], "command": "exit" },
{ "keys": ["ctrl+shift+n"], "command": "new_window" },
{ "keys": ["ctrl+shift+w"], "command": "close_window" },
{ "keys": ["ctrl+o"], "command": "prompt_open_file" },
{ "keys": ["ctrl+shift+t"], "command": "reopen_last_file" },
{ "keys": ["alt+o"], "command": "switch_file", "args": {"extensions": ["cpp", "cxx", "cc", "c", "hpp", "hxx", "h", "ipp", "inl", "m", "mm"]} },
{ "keys": ["ctrl+n"], "command": "new_file" },
{ "keys": ["ctrl+s"], "command": "save" },
@plasticbrain
plasticbrain / gist:3717330
Created September 13, 2012 20:22
Sublime Text: User Preferences
{
"font_size": 10.0,
"ignored_packages":
[
"Vintage",
"Color Highlighter"
],
"ignored_words":
[
"Affiliate's",
@plasticbrain
plasticbrain / gist:3717336
Created September 13, 2012 20:23
Sublime Text: Default Preferences
// While you can edit this file, it's best to put your changes in
// "User/Preferences.sublime-settings", which overrides the settings in here.
//
// Settings may also be placed in file type specific options files, for
// example, in Packages/Python/Python.sublime-settings for python files.
{
// Sets the colors used within the text area
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
// Note that the font_face and font_size are overriden in the platform
@plasticbrain
plasticbrain / gist:3798262
Created September 28, 2012 06:24
PHP: Get user's real IP address
function get_ip() {
if( isset($_SERVER['HTTP_CLIENT_IP']) ) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif( isset($_SERVER['HTTP_X_FORWARDED_FOR']) ) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = @$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
@plasticbrain
plasticbrain / gist:3863711
Created October 10, 2012 07:24 — forked from lucasfais/gist:1207002
Sublime Text: Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt