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
/** usage */ | |
// list of values that we accept | |
$array = [2,4,8,16,32,64,128,256,512,1024,2048]; | |
round_up(18,$array); // returns 32 | |
round_up(2,$array); // returns 2 | |
round_up(2049,$array); // returns false | |
// pass a number and an array, find the next highest number (kind of like the price is right, but backwards - "closest without going under") | |
function round_up($number,Array $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
<?php | |
/* | |
* Plugin Name: Example Modify Price | |
*/ | |
class Example_Modify_Price { | |
private static $instance; | |
public static function register() { | |
if (self::$instance == null) { |
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 React = require('react'); | |
var request = require('superagent'); | |
var Header = require('../../common/components/header.jsx'); | |
var Button = require('../../common/components/button.jsx'); | |
var App = React.createClass({ | |
getInitialState: function() { | |
return { |
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
The MIT License (MIT) | |
Copyright (c) 2015 Justin Perry | |
Permission is hereby granted, free of charge, to any person obtaining a copy of | |
this software and associated documentation files (the "Software"), to deal in | |
the Software without restriction, including without limitation the rights to | |
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | |
the Software, and to permit persons to whom the Software is furnished to do so, | |
subject to the following conditions: |
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 createRandomString(minLen, maxLen) { | |
var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split(''), | |
stringLen = Math.floor(Math.random() * (maxLen - minLen + 1)) + minLen, | |
string = ''; | |
for(var i = 0; i < stringLen; i++) { | |
string += alphabet[Math.floor(Math.random() * alphabet.length)]; | |
} | |
return 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
<?php | |
// Establish a new database connection | |
// Barebones edition | |
$db = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME, DB_USER, DB_PASS); | |
// Advanced edition | |
$db = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8;port=3306', DB_USER, DB_PASS); | |
?> |
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 | |
// Assuming that database connection is already open | |
// Let's say a user is allowed to provide a table name to query from | |
$tableName = trim($_GET['tableName']); | |
// This would NOT work (no good!) | |
$stmt = $db->prepare("SELECT user, id, email FROM :table WHERE id > 1000"); | |
$stmt->bindParam(':table', $tableName); | |
$stmt->execute(); |
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
-- a quick LUA access script for nginx to check IP addresses against an | |
-- `ip_blacklist` set in Redis, and if a match is found send a HTTP 403. | |
-- | |
-- allows for a common blacklist to be shared between a bunch of nginx | |
-- web servers using a remote redis instance. lookups are cached for a | |
-- configurable period of time. | |
-- | |
-- block an ip: | |
-- redis-cli SADD ip_blacklist 10.1.1.1 | |
-- remove an ip: |
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 Foundation | |
#if os(iOS) | |
import UIKit | |
#else | |
import AppKit | |
#endif | |
/// Return string value currently on clipboard | |
func getPasteboardContents() -> 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 myComponents = myComponents || {}; | |
var el = wp.element.createElement; | |
var __ = wp.i18n.__; | |
myComponents.inputComponent = function( id, attributes, changeCallback ) { | |
return el( | |
'input', | |
{ | |
id: id + '-control', | |
value: attributes.who, |