Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Yuan, Jun mediter

🎯
Focusing
Block or report user

Report or block mediter

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mediter
mediter / tableview-background.swift
Created May 19, 2018
[Table View Background] #ios #swift #UITableView
View tableview-background.swift
tableView.backgroundColor = UIColor(red:1, green:1, blue:1, alpha:1.00)
let backgroundImageView = UIImageView(frame: view.bounds)
backgroundImageView.image = UIImage(named: "background")
backgroundImageView.alpha = 0.5
tableView.backgroundView = backgroundImageView
@mediter
mediter / statusbar.swift
Last active May 19, 2018
[Status Bar Height] #swift #ios #statusbar
View statusbar.swift
// get the height of the status bar
let statusBarHeight = UIApplication.shared.statusBarFrame.height
@mediter
mediter / app_doc_path.swift
Created May 20, 2018
[App Document Directory] #swift #persistence
View app_doc_path.swift
// MARK: - Data Persistence
func documentsDirectory() -> URL {
let paths = FileManager.default.urls(for: .documentDirectory,
in: .userDomainMask)
return paths[0]
}
func dataFilePath() -> URL {
return documentsDirectory().appendingPathComponent("Checklists.plist")
}
@mediter
mediter / error.swift
Created May 20, 2018
[Error Handling] #swift #error
View error.swift
import Foundation
do {
//要做一些操作
let str = try NSString(contentsOfFile: filePath,encoding:   NSUTF8StringEncoding)//要尝试做的事情
} catch let err as NSError {//如果失败则进入catch代码块
@mediter
mediter / wp_archive_title.php
Created May 22, 2018
[Remove “Category:”, “Tag:”, “Author:” from the_archive_title] #wordpress #archive #page-title
View wp_archive_title.php
add_filter( 'get_the_archive_title', function ($title) {
if ( is_category() ) {
$title = single_cat_title( '', false );
} elseif ( is_tag() ) {
$title = single_tag_title( '', false );
@mediter
mediter / regex_matches.swift
Last active May 24, 2018
[RegEx Matches] #swift #regex
View regex_matches.swift
Swift 3 (Xcode 8)
```swift
func matches(for regex: String, in text: String) -> [String] {
do {
let regex = try NSRegularExpression(pattern: regex)
let nsString = text as NSString
let results = regex.matches(in: text, range: NSRange(location: 0, length: nsString.length))
return results.map { nsString.substring(with: $0.range)}
} catch let error {
@mediter
mediter / wp_dev_func.php
Created Jul 10, 2018
[WordPress Function in Parent and Child Theme] #WordPress #PHP #Theme
View wp_dev_func.php
// To write a pluggable function, you simply enclose it in a conditional tag to check if a function with that name has already been run:
<?php
if ( ! function_exists ( 'my_function' ) ) {
function my_function() {
// Contents of your function here.
}
}
?>
Then when you come to write a function in your child theme which you want to override the one in the parent theme, you just give it the same name as the one in the parent theme:
@mediter
mediter / wp-excerpt.php
Created Jul 10, 2018
[WordPress Post Excerpt and Truncation] #WordPress #Excerpt
View wp-excerpt.php
<ul>
<?php
$args=array(
'cat' => 1, // 分类ID
'posts_per_page' => 10, // 显示篇数
);
query_posts($args);
if(have_posts()) : while (have_posts()) : the_post();
?>
@mediter
mediter / wp_reg_sidebar.php
Last active Jul 11, 2018
[WordPress Sidebars] #WordPress #PHP #sidebar
View wp_reg_sidebar.php
register sidebar in functions.php
registering a sidebar is just defining a container
if( function_exists('register_sidebar') ) {
register_sidebar(array(
'name' => 'spage',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h3>',
'after_title' => '</h3>'
@mediter
mediter / bash_for_touch_echo.md
Last active Dec 4, 2018
[bash for-loop with echo] #bash #for-loop #touch #echo
View bash_for_touch_echo.md

for-loop with echo

for model in "artists" "galleries" "paintings"
do
    mkdir -p $(echo views/api/v1/$model)
    for verb in "index" "show"
    do
        touch $(echo views/api/v1/$model/$verb.json.jbuilder)
    done
You can’t perform that action at this time.