Skip to content

Instantly share code, notes, and snippets.

View karloscarweber's full-sized avatar
📱
Building

Karl Weber karloscarweber

📱
Building
View GitHub Profile
@karloscarweber
karloscarweber / islegit.php
Last active August 29, 2015 13:56
_islegit() checks if a variable is set and not empty. eliminates a lot of extra code in the long run. Seems kinda silly if you just take it as it is.
<?php
/*
Checks if something is set and not empty
Pass the variable as a reference to truly check its
legitness.
*/
function _islegit(&$variable = null)
{
if($variable) {
@karloscarweber
karloscarweber / postgre.php
Created December 11, 2013 17:54
This function reads your DATABASE_URL config var and returns a connection string suitable for pg_connect on Heroku.
<?php
# This function reads your DATABASE_URL config var and returns a connection
# string suitable for pg_connect. Put this in your app.
function pg_connection_string_from_database_url() {
extract(parse_url($_ENV["DATABASE_URL"]));
return "user=$user password=$pass host=$host dbname=" . substr($path, 1); # <- you may want to add sslmode=require there too
}
# Here we establish the connection. Yes, that's all.
$pg_conn = pg_connect(pg_connection_string_from_database_url());
@karloscarweber
karloscarweber / ready.js
Created October 24, 2013 16:30
All th ways to make a document.ready() event listener for Jquery. see: http://api.jquery.com/ready/ I've had to look this up enough times that I decided to store it somewhere. I don't know why I always forget
/*Classic way*/ // $( document ).ready( handler )
$( document ).ready( function( ) {
// do something.
} )
/* Short Way */ // $( handler )
$( function( ) {
// do something
@karloscarweber
karloscarweber / mandrill.php
Last active July 13, 2017 23:32
A CakePHP 2.0 Component That integrates with the Mandrill API. Just enough to get you started, Fill in the gaps.
<?php
// App/controllers/components/mandrill.php
class MandrillComponent extends Object
{
var $components = array('Session', 'RestRequest');
var $settings = array(
'host' => 'smtp.mandrillapp.com',
'port' => '587',
'username' => 'username',
@karloscarweber
karloscarweber / gist:6383452
Last active December 21, 2015 23:39
Code Styling for PHP Documentation
<?php
//Some Coding Standards that I want to follow. I might as well write it down.
/*
* Functions
*/
/*
* Function Names should be lowerecased multiple words should be seperated by underscores
* private methods / functions should begin with an underscore
@karloscarweber
karloscarweber / addDots.js
Last active December 17, 2015 03:38
Adds a dot to indicate cents.
var intervalID = 0;
timer = 0;
// add's comma's to every third decimal place from the end
intervalID = window.setInterval(function(){
addDots(document.getElementById("bidAmount"))
}, 1);
$('#bidAmount').onKeyUp(delay());
function delay() {
@karloscarweber
karloscarweber / README.md
Last active July 29, 2016 21:55
A simple Base REST api connector thingy.

Base CRM PHP REST API thingy

So, this is a collection of classes tha makes it way easier to work with most of the base api, getbase.com.

It's organized as follows

index.php

obviously the controller. it uses simple GET urls to determine get, post, put, and delete requests, as well as which resource is being requested.

@karloscarweber
karloscarweber / kowFocus.js
Created February 21, 2013 16:48
A little javascript to echo which element has the focus.
// kowFocus.js
// A little javascript to echo which element has the focus hardcore. (Uses Jquery)
// written by: Karl Oscar Weber, http://karloscarweber.com
setTimeout(function(){
$('*').on('focus', function(){
console.log($(this));
})
}, 2000);
@karloscarweber
karloscarweber / panelSwitch.html
Created December 13, 2012 17:47
A jQuery panel switcher. It alternates between different panelSlides
<div class="panel-container">
<a class="panelSwitch">
<h5>button</h5>
</a><!-- End of .panelSwitch -->
<div style="" class="panelBoard">
<!-- Fill me with any content -->
</div><!-- End of .panelBoard -->
@karloscarweber
karloscarweber / jquery.function.js
Created April 15, 2012 00:34
A Jquery Function Extention boilerplate
// Jquery Function BoilerPlate for newbies
//
//
// Surrounded by parentheses to allow anonymous founcitons on the inside
(function($){ // pass the jquery pseudo variable "$" into the function in order to create it's awesomeness.
$.fn.yourFucntion = function(userConfig) {
// please note, the "this" variable in the current scope will refer to the