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 | |
/* | |
A simple friendly date parser for upcoming dates | |
in the near future. | |
*/ | |
function friendly_date( $date_string ) { | |
$date = new DateTime( $date_string ); |
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
var moves = ['rock','paper','scissors'], | |
results = ['we draw','you loose','you win'], | |
user_move = moves.indexOf(prompt(moves+'?')), | |
computer_move, | |
result; | |
while (user_move > -1) { | |
computer_move = Math.round(Math.random()*2); | |
result = results[ (2*user_move+computer_move)%3 ]; |
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
1234,255 | |
1111,244 | |
0000,221 | |
1212,212 | |
7777,203 | |
1004,199 | |
2000,199 | |
4444,196 | |
2222,195 | |
6969,195 |
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 | |
// only allow a single post to be sticky | |
function post_published_notification( $ID, $post ) { | |
global $_POST; | |
if (array_key_exists('sticky', $_POST)) { | |
update_option('sticky_posts', array() ); | |
} | |
} | |
add_action( 'publish_post', 'post_published_notification', 10, 2 ); |
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
struct Person { | |
let age = 0 | |
} | |
let people = ["tom": Person(age: 12), "dick": Person(age: 7), "harry": Person(age: 50)] | |
var people_array = [Person](people.values) //convert to array | |
people_array.sort({ $0.age > $1.age }) //sort the 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
import UIKit | |
class ViewController: UIPageViewController, UIPageViewControllerDataSource { | |
var pages = [UIViewController]() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.dataSource = self | |
pages = [ |
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
private func findOrCreate<T:NSManagedObject>( managedObjType:T.Type, id: NSNumber ) -> T { | |
let className = toString(T).pathExtension | |
let fetchRequest = NSFetchRequest(entityName: className) | |
fetchRequest.predicate = NSPredicate(format: "id == %@", id ) | |
let foundManagedObjects = self.managedObjectContext?.executeFetchRequest(fetchRequest, error: nil) as? [T] | |
let managedObject = (foundManagedObjects == nil || foundManagedObjects!.isEmpty) | |
? NSEntityDescription.insertNewObjectForEntityForName(className, inManagedObjectContext: self.managedObjectContext!) as? T | |
: foundManagedObjects!.first | |
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
<style> | |
#images * { | |
width: 140px; | |
} | |
</style> | |
<p id='status'></p> | |
<div id='images'></div> | |
<button onclick='fusker.start()'>--go--</button> |
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
function scroll_to(element, duration = 500, easing = 'easeInOutQuart') { | |
var start_pos = document.body.scrollTop, | |
end_pos = element.offsetTop, | |
distance = end_pos - start_pos, | |
start_time = Date.now(), | |
end_time = start_time + duration; | |
var easingFunctions = { |
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
var lines = `123 -> x | |
456 -> y | |
x AND y -> d | |
x OR y -> e | |
x LSHIFT 2 -> f | |
y RSHIFT 2 -> g | |
NOT x -> h | |
NOT y -> i`.split('\n'); |
OlderNewer