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 / 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 / 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 / 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 / rest_request
Created March 4, 2014 23:38
A Rest Request component for CakePHP 2.0. I figured that I use this component so much that I might as well make it it's own repository.
<?php
// App/controllers/components/rest_request.php
// shamelessly lifted from: http://www.gen-x-design.com/archives/making-restful-requests-in-php/
// slightly modified
class RestRequestComponent extends Object
{
var $components = array('Session');
protected $url;
protected $verb;
@karloscarweber
karloscarweber / RealmModel.swift
Last active August 29, 2015 14:06
Sample Realm Model in Swift
import Realm
class ModelName: RLMObject {
dynamic name: String = ""
dynamic value: Int = 0
}
@karloscarweber
karloscarweber / UIBorderedLabel.swift
Created September 13, 2014 23:39
UILabel subclass that makes setting padding really easy.
//
// UIBorderedLabel.swift
// standToMake
//
// Created by Karl Oscar Weber on 9/13/14.
// Copyright (c) 2014 Karl Oscar Weber. All rights reserved.
//
// Thanks to: http://userflex.wordpress.com/2012/04/05/uilabel-custom-insets/
import UIKit
<?php
$view = new View($this, false);
$view->set(compact('some', 'vars'));
$html = $view->render('view_name');
.my-link {
text-decoration: underline;
}
@karloscarweber
karloscarweber / dither.js
Created June 15, 2018 14:38 — forked from mattdesl/dither.js
dither-blob.js
const sketcher = require('canvas-sketch-tool'); // not yet public
// Import geometry & utilities
const createRegl = require('regl');
const createPrimitive = require('primitive-icosphere');
const createCamera = require('perspective-camera');
const glslify = require('glslify');
const hexRgb = require('hex-rgb');
// Utility to convert hex string to [ r, g, b] floats
// This will open up a prompt for text to send to a console session on digital ocean
// Useful for long passwords
(function () {
var t = prompt("Enter text to be sent to console, (This wont send the enter keystroke)").split("");
function f() {
var character = t.shift();
var i=[];
var code = character.charCodeAt();
var needs_shift = "!@#$%^&*()_+{}:\"<>?~|".indexOf(character) !== -1