Skip to content

Instantly share code, notes, and snippets.

View nguyenvanduocit's full-sized avatar
🌴
On vacation

Duoc Nguyen nguyenvanduocit

🌴
On vacation
View GitHub Profile
@nguyenvanduocit
nguyenvanduocit / Soundcloud.class.php
Created June 15, 2013 14:11
get stream URL from soundcloud
<?php
class SoundcloudAPI
{
protected $clientID;
function __construct() {
$this->clientID = "69b6a6bc4f7d483fd21b170137a9cd51";
}
function GetTrackLink($id)
{
@nguyenvanduocit
nguyenvanduocit / wordpress.admin.editor.disableWYSIWYG.php
Created June 20, 2013 02:46
Disable WYSIWYG Editor For Custom Post Types If you need to make sure that your custom post type doesn’t have the ‘visual’ tab, you can easily diable it.
add_filter( 'user_can_richedit', 'disable_for_cpt' );
function disable_for_cpt( $default ) {
global $post;
if ( 'movie' == get_post_type( $post ) )
return false;
return $default;
}
@nguyenvanduocit
nguyenvanduocit / Wordpress.admin.post.ShowPostOfAuthorOnly.php
Created June 20, 2013 02:49
Show Authors Their Own Posts in Admin You can redirect the normal All Posts pages to a version that only displays the current user’s posts. (Similar to this post). Users will not be able to get back to the ‘all’ view, as in the other sample. Users are not prevented from changing the author ID in the URL and viewing another user’s posts.
add_action( 'load-edit.php', 'posts_for_current_author' );
function posts_for_current_author() {
global $user_ID;
/*if current user is an 'administrator' do nothing*/
//if ( current_user_can( 'add_users' ) ) return;
/*if current user is an 'administrator' or 'editor' do nothing*/
//if ( current_user_can( 'edit_others_pages' ) ) return;
@nguyenvanduocit
nguyenvanduocit / wordperss.admin.post.customPublishBox
Created June 20, 2013 03:43
Add Post Options To “Publish” Meta Box We often add custom meta boxes to a page or post in order to save specific kinds of data. In some cases, the best place to add those fields really isn’t in some box that gets added to the end of the page. The option needs to be in a bit more prominent location. Fortunately, it’s possible to add text or form…
add_action( 'post_submitbox_misc_actions', 'article_or_box' );
add_action( 'save_post', 'save_article_or_box' );
function article_or_box() {
global $post;
if (get_post_type($post) == 'post') {
echo '<div class="misc-pub-section misc-pub-section-last" style="border-top: 1px solid #eee;">';
wp_nonce_field( plugin_basename(__FILE__), 'article_or_box_nonce' );
$val = get_post_meta( $post->ID, '_article_or_box', true ) ? get_post_meta( $post->ID, '_article_or_box', true ) : 'article';
echo '<input type="radio" name="article_or_box" id="article_or_box-article" value="article" '.checked($val,'article',false).' /> <label for="article_or_box-article" class="select-it">Article</label><br />';
echo '<input type="radio" name="article_or_box" id="article_or_box-box" value="box" '.checked($val,'box',false).'/> <label for="article_or_box-box" class="select-it">Box</label>';
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
# built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
*.class
classes/
@nguyenvanduocit
nguyenvanduocit / Launch the 'Add Contact'
Created June 1, 2014 19:07
Launch the 'Add Contact'
// Add listener so your activity gets called back upon completion of action,
// in this case with ability to get handle to newly added contact
myActivity.addActivityListener(someActivityListener);
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
// Just two examples of information you can send to pre-fill out data for the
// user. See android.provider.ContactsContract.Intents.Insert for the complete
// list.
<?php
// make api call
$response = (new FacebookRequest(
$session, 'POST', '/me/feed', array(
'name' => 'Facebook API: Posting a Status Update Using PHP SDK 4.0.x',
'caption' => "I'm rewriting old tutorials to work with the new PHP SDK 4.0 and Graph API 2.0.",
'link' => 'https://muatocroi.com',
'message' => 'Check out my new tutorial'
)
<?php
class Curl {
/**
* cURL request method
*
* @var string
*/
protected $_method = 'GET';
@nguyenvanduocit
nguyenvanduocit / ShareUtils.java
Created July 23, 2014 03:23
Android Share action
/*
* Copyright 2014 Uwe Trottmann
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software