Skip to content

Instantly share code, notes, and snippets.

View RShergold's full-sized avatar
💭
Currently alive

Remi Shergold RShergold

💭
Currently alive
View GitHub Profile
<?php
/*
A simple friendly date parser for upcoming dates
in the near future.
*/
function friendly_date( $date_string ) {
$date = new DateTime( $date_string );
@RShergold
RShergold / rock-paper-scissors.js
Last active August 29, 2015 14:07
rock paper scissors javascript - code golf - small as possible
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 ];
@RShergold
RShergold / gist:217962b34da42c54b395
Created October 11, 2014 13:38
pin codes by frequency
1234,255
1111,244
0000,221
1212,212
7777,203
1004,199
2000,199
4444,196
2222,195
6969,195
<?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 );
@RShergold
RShergold / sort_dictionary_of_objects.swift
Last active August 29, 2015 14:16
swift - sort dictionary of objects
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
@RShergold
RShergold / gist:ff04fb705410c91726bb
Last active August 29, 2015 14:21
PageViewController minimal
import UIKit
class ViewController: UIPageViewController, UIPageViewControllerDataSource {
var pages = [UIViewController]()
override func viewDidLoad() {
super.viewDidLoad()
self.dataSource = self
pages = [
@RShergold
RShergold / gist:d088b45515e1c3bb293f
Last active August 29, 2015 14:21
generic findOrCreate function for NSManagedObjects with an id
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
@RShergold
RShergold / fusker.html
Last active August 29, 2015 14:26
Imgur fusker
<style>
#images * {
width: 140px;
}
</style>
<p id='status'></p>
<div id='images'></div>
<button onclick='fusker.start()'>--go--</button>
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 = {
@RShergold
RShergold / adventofcode.js
Last active December 10, 2015 15:55
adventofcode day 7
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');