This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Scanner scanner = null; | |
try{ | |
// change filePath to your your source | |
scanner = new Scanner(new BufferedReader(new FileReader(filePath))); | |
Pattern p = Pattern.compile("--REGEX--"); // enter your regular expression | |
while (scanner.hasNext()) { | |
Matcher m = p.matcher(scanner.nextLine()); | |
while (m.find()) { | |
String result = m.group(); | |
// do something with your result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Singleton pattern to ensure a single controller | |
*/ | |
private static MainController controller = null; | |
public static synchronized MainController Current() { | |
if (controller == null) { | |
controller = new MainController(); | |
} | |
return controller; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Resources { | |
public static String FILENAME = "fileName"; | |
public static Font STANDARD_FONT = new Font("DejaVu Sans", Font.PLAIN, 12); | |
public static class Colors { | |
public static Color Blue = new Color(0.3f, 0.5f, 1f); | |
public static Color Red = new Color(1f, 0.3f, 0.1f); | |
public static Color Green = new Color(0.3f, 1f, 0.5f); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// It is recommended to use an interface when using a repository. | |
// This way you can change the implementation without affecting the usage | |
public interface IRepository { | |
public void connect(); | |
} | |
public class Repository implements IRepository { | |
// get the instance of the controller |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void setModelProperty(String propertyName, Object newValue) { | |
for (AbstractModel model : registeredModels) { | |
try { | |
Method method = model.getClass().getMethod("set" + propertyName, new Class[] { newValue.getClass() }); | |
method.invoke(model, newValue); | |
} catch (Exception ex) { | |
// TODO Handle exception. | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function post_thumbdail($full){ | |
if ( has_post_thumbnail() ) { | |
echo "<aside><a href='".get_permalink()."' title='".get_the_title()."' rel='canonical'>"; | |
the_post_thumbnail($full); | |
echo "</a></aside>"; | |
}else{ | |
if( $full == 'full' ) return; | |
$attachments = get_posts( array( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// get current post categories and tags | |
$categories = get_the_category($post->ID); | |
$tags = get_the_tags($post->ID); | |
if ($categories || $tags) { | |
$category_ids = array(); | |
if($categories) | |
foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id; | |
$tag_ids = array(); | |
if($tags) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // Get RSS Feed(s) | |
include_once(ABSPATH . WPINC . '/feed.php'); | |
$feed = array(); | |
$feed += add('http://vilmosioo.co.uk/feed/', 'wp'); | |
$feed += add('http://pinterest.com/ioowilly/feed.rss', 'pinterest'); | |
$feed += add('http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=ioowilly', 'twitter'); | |
$feed += add('http://www.goodreads.com/user/updates_rss/4165963?key=a5d32462cef6d00b08e095ba9b74d3e03c310841', 'goodreads'); | |
krsort($feed); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(is_singular()) { ?> | |
<meta name="twitter:card" content="summary"> | |
<meta name="twitter:url" content="<?php echo get_permalink($post->ID); ?>"> | |
<meta name="twitter:title" content="<?php echo $post->post_title;?>"> | |
<meta name="twitter:description" content="<?php echo substr( $post->post_content, 0, 150 );?>"> | |
<?php | |
// you will need to hardcode this or use a plugin that allows twitter info to be added to authors | |
$twitter = the_author_meta('twitter', $post->post_author); | |
if($twitter){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Github API helper class | |
* | |
* Uses the github api to retrieve public gists, repos or commits for a specific user | |
*/ | |
class Github_API{ | |
static function get_data($url){ | |
$base = "https://api.github.com/"; | |
$response = wp_remote_get($base . $url, array( 'sslverify' => false )); |
OlderNewer