Skip to content

Instantly share code, notes, and snippets.

<?php
function correctYYMMDD($input){
$input = substr($input, 0, 6);
//is it already in correct format?
if(preg_match('/[0-9][0-9](1[0-2]|0[1-9])([0-2][0-9]|3[01])/', $input)) return $input;
//let's reverse it.
$rev = array();
$rev['yy'] = substr($input, 4, 2);
<?php
protected static function validatePNumber($pnumber) {
/* Check valid form (existing month and day) */
if (!preg_match("/^[0-9]{2}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))[0-9]{4}$/", $pnumber)) return false;
/* Calculate check sum and check wether or not the control digit is correct */
$sum = 0;
$x = 0;
for ($i = 0; $i < 10; $i++) {
@Sleavely
Sleavely / command.js
Last active December 27, 2015 11:59
Backtick - Prettify
(function a() {
var a, b;
Array.prototype.forEach.call(document.querySelectorAll("pre"), function (a) {
a.className = "prettyprint linenums"
}), a = document.createElement("script"), a.onload = function () {
prettyPrint()
}, a.src = "https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?skin=sunburst", document.body.appendChild(a)
})();
@Sleavely
Sleavely / command.js
Last active January 1, 2016 04:49 — forked from JoelBesada/README.md
Premailer bookmarklet
(function(){
document.body.appendChild(document.createElement('script')).src='http://premailer.dialect.ca/inc/bookmarklet-1.0.js';
})();
<?php
print '<meta charset="utf8" /><pre>';
require_once('oauth.php');
$settings = array(
'oauth_access_token' => "",
'oauth_access_token_secret' => "",
'consumer_key' => "",
'consumer_secret' => ""
);
@Sleavely
Sleavely / form.php
Last active January 3, 2016 03:08
Drupal 7 form file processing
<?php
function mymodule_form($form, &$form_state) {
// [...]
$form['attachment'] = array(
'#type' => 'file',
'#title' => t('Attachment'),
);
<?php
use Carbon\Carbon;
class ApiV1Controller extends BaseController {
public $endpoints = array(
'items' => 'https://storage.googleapis.com/nacleanopenworldprodshards/ItemTemplates_cleanopenworldprodeu2.json',
'nations' => 'https://storage.googleapis.com/nacleanopenworldprodshards/Nations_cleanopenworldprodeu2.json',
'ports' => 'https://storage.googleapis.com/nacleanopenworldprodshards/Ports_cleanopenworldprodeu2.json',
'shops' => 'https://storage.googleapis.com/nacleanopenworldprodshards/Shops_cleanopenworldprodeu2.json',
#!/bin/bash
# Change the server address. Run in the /logs/ directory.
apihost="http://api.localhost";
logfile=$(ls -tr xmpp_* | tail -1);
# Dont edit below this line :)
vcard="";
# Using awk to flush every line separately to avoid buffering issues. I think.
tail -f "$logfile" | awk '{print $0; fflush()}' | while read -r line
@Sleavely
Sleavely / eu-pvp3.md
Last active April 27, 2016 07:23
Naval Action Liaisons

Non-exhaustive list of liaisons and prominent figures from the clans and nationalities on Naval Action EU PVP Mirror 3.

Denmark-Norway

*crickets*

France

EFC

  • Rakk