Skip to content

Instantly share code, notes, and snippets.

View zirosas's full-sized avatar

Jiro Sasamoto zirosas

View GitHub Profile
@zirosas
zirosas / WordPress Admin Dashboad
Created June 26, 2013 20:02
WordPress Admin Dashboad modification
function remove_dashboard_widgets() {
// Globalize the metaboxes array, this holds all the widgets for wp-admin
global $wp_meta_boxes;
// Remove the incomming links widget
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
// Remove right now
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth ) {
// load image and get image size
$img = imagecreatefromjpeg( "{$pathToImages}" );
$width = imagesx( $img );
$height = imagesy( $img );
// calculate thumbnail size
$new_width = $thumbWidth;
$new_height = floor( $height * ( $thumbWidth / $width ) );
// create a new temporary image
$tmp_img = imagecreatetruecolor( $new_width, $new_height );
@zirosas
zirosas / s3 uploading
Created June 26, 2013 20:16
PHP s3 uploading, require (S3.php)
function s3_uploading ($flname, $vid, $cover) {
if($_FILES[$flname]["name"]) {
$photodir;
try {
if ((($_FILES[$flname]["type"] == "image/gif") || ($_FILES[$flname]["type"] == "image/jpg") || ($_FILES[$flname]["type"] == "image/jpeg") || ($_FILES[$flname]["type"] == "image/pjpeg")) && ($_FILES[$flname]["size"] < 1000000)) {
if ($_FILES[$flname]["error"] > 0) {
echo "Return Code: " . $_FILES[$flname]["error"] . "<br />";
}
else {
@zirosas
zirosas / WordPress theme_support
Created June 26, 2013 20:34
WordPress theme_support
add_theme_support('menus');
register_sidebar(
array(
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
)
);
@zirosas
zirosas / Custom option table
Created June 26, 2013 20:51
WordPress Custom option table
if(strlen($array['option']) > 0) {
$optLen = strlen($array['option']);
$optionBit = $array['option'];
$strSql = "SELECT ".$wpdb->prefix."option . * FROM ".$wpdb->prefix."option ORDER BY ".$wpdb->prefix."option.option_id";
$wpdb->query($strSql);
$options = $wpdb->get_results($strSql,ARRAY_A);
if(count($options) > 0) {
$retNo = 0;
$i = 0;
foreach((array)$options as $option) {
@zirosas
zirosas / mysqldump
Last active December 19, 2015 03:18
mysql import
mysql -u [username] -p [database_name] < [dumpfilename.sql]
@zirosas
zirosas / Rails form
Last active December 19, 2015 09:09
Override the class name in the form_for helper. keep checkbox and label on same line.
Override the class name in the form_for helper.
<%= form_for("model", :url => model_action_path, :html => { :class => "form-horizontal" } ) do |f| %>
keep checkbox and label on same line.
:class => "checkbox inline" to label
@zirosas
zirosas / Postgresql command
Last active December 19, 2015 09:09
Postgresql command
\c db_name : to connect to a certain database
\l : lists all databases
\dt : lists all tables in the current database
\d+ tablename : display table schema
heroku pg:psql : connect to Heroku psql
@zirosas
zirosas / Devise Error Messages for Bootstrap
Created July 5, 2013 08:28
Devise Error Messages for Bootstrap
/app/helpers/devise_helper.rb
module DeviseHelper
def devise_error_messages!
return '' if resource.errors.empty?
messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
sentence = I18n.t('errors.messages.not_saved',
count: resource.errors.count,
resource: resource.class.model_name.human.downcase)
@zirosas
zirosas / To add a CSS class to specific input
Created July 9, 2013 09:26
To add a CSS class to specific input
jQuery(document).ready(function($) { //noconflict wrapper
$('input#submit').addClass('btn btn-info');
});//end noconflict