Skip to content

Instantly share code, notes, and snippets.

View Ciantic's full-sized avatar

Jari Pennanen Ciantic

View GitHub Profile
@Ciantic
Ciantic / taxonomy_select.php
Last active August 29, 2015 13:59
Shows the taxonomy selection in admin as <select> box
<?php
// Author: Jari Pennanen
// License: Public Domain
// 2014-04-16
/**
* Display taxonomy selection in admin as select box
*
* @param WP_Post $post
* @param array $box
@Ciantic
Ciantic / gist:8a09107fcd9bed8bede0
Created June 24, 2014 16:41
WordPress select and checkboxes metabox callback
<?php
/**
* Show taxonomy selection in WordPress admin as single <select> box or checkboxes
*
* @author Jari Pennanen / https://github.com/ciantic
* @license Public Domain
**/
// Usage example:
register_taxonomy("my_taxonomy", array("post"), array(
@Ciantic
Ciantic / formatTime.ts
Created June 29, 2014 21:41
Format time HH:MM
// total in seconds
function formatTime(total: number): string {
// If the number is float ceiling gives best result
var total = Math.ceil(total),
mins = Math.floor(total / 60),
secs = Math.floor(total - mins * 60),
m = ("000" + mins).slice(-2),
s = ("000" + secs).slice(-2);
return m + ":" + s;
@Ciantic
Ciantic / MyElement.ts
Last active January 28, 2016 18:25
CustomElement inheritance in TypeScript (before it's fixed)
import customelement = require('./customelement');
export class MyElement extends customelement.CustomHTMLElement {
public myTest() {
// "this" is fully qualified, includes all methods e.g. addEventListener, dispatchEvent
console.log("this", this);
console.dir(this);
}
}
@Ciantic
Ciantic / parse-format-isodatetime.js
Last active August 29, 2015 14:07
Parse and format iso datetime
/**
* Parse ISO datetime
*
* 2014-10-18 15:30:30
* 2014-10-18T15:30:30
* 2014-10-18
*/
function parseIsoDatetime(dtstr) {
var dt = dtstr.split(/[: T-]/).map(parseFloat);
@Ciantic
Ciantic / JooqModule.scala
Last active September 11, 2017 16:57
injection with DB.getConnection fails
import javax.inject.{Singleton, Inject}
import com.google.inject.AbstractModule
import play.api.db.{DBApi}
import play.api.{Logger, Configuration}
import org.jooq.util.GenerationTool
import org.jooq.util.jaxb.{Target, Database, Generator}
import play.api.db.evolutions.EvolutionsModule
import play.api.Play.current
@Ciantic
Ciantic / insert_or_get_term_id.php
Created September 8, 2015 05:54
Insert or Get Term ID
<?php
/**
* (WordPress) Insert or get term id
*
* @return int Term ID (0 no term was inserted or found)
*/
function __wp_insert_or_get_term_id($name, $taxonomy, $parent = 0) {
if (!($term = get_term_by("name", $name, $taxonomy))) {
$insert = wp_insert_term($name, $taxonomy, array(
@Ciantic
Ciantic / export_them_all.php
Last active January 30, 2016 19:10
WordPress - Export taxonomies or categories
<?php
function just_export_damn_taxonomies($taxs = array(), $include_cats = false, $include_tags = false) {
$WXR_VERSION = '1.2';
// functions from 'wp-admin/includes/export.php'
function wxr_cdata($str) {
if (seems_utf8 ( $str ) == false)
$str = utf8_encode ( $str );
@Ciantic
Ciantic / ensime.ts
Last active March 5, 2016 20:43
Ensime start
import * as http from 'http';
import * as https from 'https';
import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
import { spawn, ChildProcess } from 'child_process';
import * as when from 'when'; // when package
import * as which from 'which'; // which package
@Ciantic
Ciantic / import-wp-db.sh
Last active March 16, 2016 10:34
Export WordPress database to file, and then rsync to its destination
#!/bin/bash
wpdir=public_html
dbfile=db-joawsefj3j14.sql
wpconfig=$wpdir/wp-config.php
if [ ! -f "$wpconfig" ]; then
echo "$wpconfig not found."
exit
fi