Skip to content

Instantly share code, notes, and snippets.

Ben Klein bklein01

Block or report user

Report or block bklein01

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bklein01
bklein01 / excerpt.md
Created Jul 23, 2019 — forked from stankusl/excerpt.md
Text Excerpt PHP function
View excerpt.md

Function:

function shorten_text($text, $max_length = 140, $cut_off = '...', $keep_word = false)
{
    if(strlen($text) <= $max_length) {
        return $text;
    }

    if(strlen($text) > $max_length) {
View php-skills-test-a.php
<?php
/*
Second Assignment
Write a script, module, application or program in PHP, which upon execution accepts
two arguments. One of those arguments should be a "total cost" (in dollars and/or cents)
and the other an "amount
provided" (also in dollars and/or cents). Return as output the change that should be
provided, by returning the count of each denomination of bills and/or coins. Extra
points for object oriented and/or advanced concepts.
View MySQL Proper case function.sql
DROP FUNCTION IF EXISTS proper;
SET GLOBAL log_bin_trust_function_creators=TRUE;
DELIMITER |
CREATE FUNCTION proper( str VARCHAR(128) )
RETURNS VARCHAR(128)
BEGIN
DECLARE c CHAR(1);
DECLARE s VARCHAR(128);
DECLARE i INT DEFAULT 1;
DECLARE bool INT DEFAULT 1;
@bklein01
bklein01 / mysql.py
Created Apr 3, 2018 — forked from naiquevin/mysql.py
Examples of Mysql programming in Python
View mysql.py
#!/usr/bin/env python
## Mysql-Python basic examples.
## All code is taken from [here](http://zetcode.com/databases/mysqlpythontutorial/)
## Gist created only for quick reference purpose
import sys
import _mysql
import MySQLdb as mdb
@bklein01
bklein01 / GetterSetterGen.php
Last active Jun 23, 2017
Copied from http://mikeangstadt.name/projects/getter-setter-gen. Used to generate Getters and Setters for a PHP class.
View GetterSetterGen.php
<?php
/**
 * Generates getter and setter methods for a PHP class
 * @author Michael Angstadt
 */
class GetterSetterGen{
  /**
   * The source code of the PHP class.
   * @var string
   */
@bklein01
bklein01 / get_attributes.sql
Created Jul 21, 2016
Quick SQL to help build TypeScript Model Classes For a Database/Restful API
View get_attributes.sql
SELECT CONCAT(column_name, ': ', (CASE data_type WHEN 'bigint' THEN 'number' WHEN 'smallint' THEN 'number' WHEN 'char' THEN 'string' WHEN 'tinyint' THEN 'number' WHEN 'int' THEN 'number' WHEN 'varchar' THEN 'string' WHEN 'text' THEN 'string' WHEN 'timestamp' THEN 'string' WHEN 'date' THEN 'string' WHEN 'datetime' THEN 'string' WHEN 'decimal' THEN 'number' END), ';')
FROM information_schema.columns
WHERE table_name = '{tablename}' AND table_schema = '{database}'
@bklein01
bklein01 / highest-prime.php
Last active Aug 29, 2015
Find the highest prime number given an argument
View highest-prime.php
<?php
class primeTest
{
private $primeArray;
public function __construct() {
$this->primeArray = array();
}
private function isPrime($n) {
You can’t perform that action at this time.