Skip to content

Instantly share code, notes, and snippets.

View bklein01's full-sized avatar

Ben Klein bklein01

View GitHub Profile
@bklein01
bklein01 / highest-prime.php
Last active August 29, 2015 14:21
Find the highest prime number given an argument
<?php
class primeTest
{
private $primeArray;
public function __construct() {
$this->primeArray = array();
}
private function isPrime($n) {
@bklein01
bklein01 / get_attributes.sql
Created July 21, 2016 19:58
Quick SQL to help build TypeScript Model Classes For a Database/Restful API
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 / GetterSetterGen.php
Last active June 23, 2017 18:38
Copied from http://mikeangstadt.name/projects/getter-setter-gen. Used to generate Getters and Setters for a PHP class.
<?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 / mysql.py
Created April 3, 2018 19:27 — forked from naiquevin/mysql.py
Examples of Mysql programming in Python
#!/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
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 / php-skills-test-a.php
Last active February 18, 2019 14:01
PHP Skills Test
<?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.
@bklein01
bklein01 / excerpt.md
Created July 23, 2019 11:15 — forked from stankusl/excerpt.md
Text Excerpt PHP function

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) {

@bklein01
bklein01 / create-aspnet-core-identity-schema.sql
Created January 31, 2023 02:03 — forked from akatakritos/create-aspnet-core-identity-schema.sql
Script to create the ASPNET core Identity tables
USE [HobbyDB]
GO
/****** Object: Table [dbo].[AspNetRoleClaims] Script Date: 6/4/2018 10:18:03 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[AspNetRoleClaims]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[AspNetRoleClaims](
@bklein01
bklein01 / merge_files.php
Created May 29, 2023 19:54
Little Utility to convert a directory of standalone php files into a Symfony controller class
<?php
$targetDir = '../public/';
$output = "<?php\n";
$output .= "namespace App\Controller\n\n";
$output .= "#[Route('/')]\n";
$output .= "class NewClass() extends AbstractController {\n";
$files = scandir($targetDir);
foreach ($files as $file) {
echo "Reading File: " . $targetDir . $file . "\n";
if (is_file($targetDir . $file)) {
@bklein01
bklein01 / generate_all_php_models_from_mysql.sql
Last active March 9, 2024 17:15
The following quick script will generate a model given a table name or all models given a database name, with all getters and setters. This is a big help for those us who develop using the new version of Symfony that removed the reverse engineering feature. Just modify two places. Working on a way to do all tables in a schema in one shot..
SELECT
CONCAT_WS(
'\n',
'namespace App\\Entity;',
'\n',
CONCAT(
'class ',
CONCAT(UCASE(SUBSTRING(s.table_name, 1, 1)), LOWER(SUBSTRING(s.table_name, 2))),
' {'
),