Skip to content

Instantly share code, notes, and snippets.

@timw4mail
timw4mail / index.php
Created August 18, 2011 19:39
PHP Kana transliterator
<?php
include("kana.php");
if(isset($_GET['in']) && isset($_GET['action']))
{
$in = $_GET['in'];
if($_GET['action'] == "to_hira")
{
$out = Kana::to_hiragana($in);
@fxm90
fxm90 / UIColor+Initializers.swift
Last active August 11, 2020 08:45
Create UIColor from RGB, RGBA, Hex or Hex-String ("#ffffff")
public extension UIColor {
/// Create color from RGB(A)
///
/// Parameters:
/// - absoluteRed: Red value (between 0 - 255)
/// - green: Green value (between 0 - 255)
/// - blue: Blue value (between 0 - 255)
/// - alpha: Blue value (between 0 - 255)
///
@carlynorama
carlynorama / dictionary_sorting.swift
Last active April 10, 2021 04:31
One line sorting of dictionaries Swift 2.1, both by key and by value examples.
let myDictionary = [
"20" : "banna",
"60" : "apple",
"30" : "cucumber",
"10" : "starfruit"
]
//assume that sort() kinda takes 2 arguments i.e. sort(dictionary element a, dictionary element b)
//woriking its way down the array (http://www.sorting-algorithms.com/bubble-sort)
//compare the 0th assumed parameter(a) with the 1st assumed parameter (b), using the key (0 after decimal)
@johnnyw
johnnyw / SKActionTransitionColor.swift
Created February 23, 2018 07:44
[SpriteKit] Custom SKAction to transition the fill/stroke color of an SKShapeNode.
import CoreGraphics
import SpriteKit
extension SKAction {
static func transitionStrokeColor(from: SKColor, to: SKColor, duration: TimeInterval) -> SKAction {
return transitionColor(from: from, to: to, duration: duration, fill: false)
}
static func transitionFillColor(from: SKColor, to: SKColor, duration: TimeInterval) -> SKAction {
@easaw
easaw / woo-check-if-has-shipping-class.php
Created August 26, 2017 00:43
Check if the Woocommerce cart has product with a certain Shipping Class
/**
* From https://isabelcastillo.com/woocommerce-check-shipping-class
* Check if the cart has product with a certain Shipping Class
* @param string $slug the shipping class slug to check for
* @return bool true if a product with the Shipping Class is found in cart
*/
function cart_has_product_with_shipping_class( $slug ) {
global $woocommerce;
@bekarice
bekarice / edit-woocommerce-checkout-template.php
Last active March 27, 2023 23:12
Add content and notices to the WooCommerce checkout - sample code
/**
* Each of these samples can be used - note that you should pick one rather than add them all.
*
* How to use WC notices: https://github.com/woothemes/woocommerce/blob/master/includes/wc-notice-functions.php#L96
* Tutorial: http://www.skyverge.com/blog/edit-woocommerce-templates/
**/
/**
* Add a content block after all notices, such as the login and coupon notices.
*
@proxpero
proxpero / Iso369_1.swift
Created March 19, 2018 13:18
A Swift 4.0 enum representing ISO 639-1 codes (used to classify languages)
// taken 2018-03-19 from wikipedia. https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
public enum Iso639_1: String {
case ab = "AB"
case aa = "AA"
case af = "AF"
case ak = "AK"
case sq = "SQ"
case am = "AM"
case ar = "AR"
// ==UserScript==
// @name Japanese Language Stack Exchange Hacks
// @namespace stackexchange
// @description Furigana, pitch accent and Japanese font-related script for the Japanese Language Stack Exchange (http://japanese.stackexchange.com)
// @include http://*japanese.stackexchange.com/*
// @include http://*anime.stackexchange.com/*
// ==/UserScript==
/*
@petenelson
petenelson / admin_head_post_edit_check.php
Created November 1, 2012 17:03
WordPress admin action hooks for listing/adding/editing posts or pages
/* actions fired when listing/adding/editing posts or pages */
/* admin_head-(hookname) */
add_action( 'admin_head-post.php', 'admin_head_post_editing' );
add_action( 'admin_head-post-new.php', 'admin_head_post_new' );
add_action( 'admin_head-edit.php', 'admin_head_post_listing' );
function admin_head_post_editing() {
echo 'you are editing a post';
}
@khanlou
khanlou / Fonts.swift
Created October 6, 2016 21:10
Print all fonts in Swift 3
UIFont.familyNames.forEach({ familyName in
let fontNames = UIFont.fontNames(forFamilyName: familyName)
print(familyName, fontNames)
})