Skip to content

Instantly share code, notes, and snippets.

@eddmann
eddmann / array_key_value
Created May 25, 2011 13:50
iterates through key-value array and returns array with defined keys values
/**
* iterates through key-value array and returns array with defined keys values
* @var Array $array
String $key
* @return Array
*/
function array_key_value($array, $key) {
$output = array();
foreach($array as $a)
@eddmann
eddmann / dump.php
Created September 10, 2012 17:35
An alternative to 'var_dump'
function dump()
{
$args = func_get_args();
echo "\n<pre style=\"border:1px solid #ccc;padding:10px;margin:10px;font:14px courier;background:whitesmoke;display:block;border-radius:4px;\">\n";
$trace = debug_backtrace(false);
$offset = (@$trace[2]['function'] === 'dump_d') ? 2 : 0;
echo "<span style=\"color:red\">" . @$trace[1+$offset]['class'] . "</span>:" .
@eddmann
eddmann / gist:4132324
Created November 22, 2012 17:37
snippets. setup SQL
CREATE TABLE `snippet` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL,
`description` text,
`snippet` text,
`tags` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
FULLTEXT KEY `search` (`title`,`description`,`snippet`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
@eddmann
eddmann / Twitter API v1.1 User Timeline JavaScript Solution
Created December 5, 2013 20:03
Get back the ability to process user timelines in JavaScript without OAuth.
var TweetFetcher = function(id)
{
this.id = id;
this.instance = 'tf_' + (new Date().getTime());
window[this.instance] = this;
};
TweetFetcher.prototype.fetch = function(cb, limit)
{
this.cb = cb;
@eddmann
eddmann / gist:9055023
Created February 17, 2014 17:24
VCF PHP
<?php
$vcard = <<<EOT
BEGIN:VCARD
VERSION:2.1
N:name;Full
FN:Full name
ORG:Company name
TITLE:Job title
END:VCARD
@eddmann
eddmann / Loops
Last active August 29, 2015 13:56
<?php
foreach ($users as $user) {
echo $user['name'] . ' [' . $user['address'] . '] (' . $user['age'] . ')';
}
for ($i = 0; $i < count($users); $i = $i + 1) {
echo $users[$i]['name'] . ' [' . $users[$i]['address'] . '] (' . $users[$i]['age'] . ')';
}
@eddmann
eddmann / gist:9411127
Created March 7, 2014 13:07
CSS Comp.
<?php
define('CSS', '/css/compiled');
define('CSS_PATH', realpath(__DIR__ . '/css'));
define('CSS_COMPILED', realpath(CSS_PATH . '/compiled'));
function css($css)
{
import java.util.*;
class PurchaseOrder {
private final boolean reserved;
private final int clientId;
public PurchaseOrder(boolean reserved, int clientId)
{
@eddmann
eddmann / arch.sh
Last active March 14, 2023 22:52
Arch Setup (with Awesome)
wifi-menu
ping www.google.com
# setup disk partitions
cfdisk.
# format disk partitions
lsblk /dev/sda
mkfs.ext4 /dev/sda1
mkfs.ext4 /dev/sda2
@eddmann
eddmann / oop.js
Last active April 28, 2016 08:38
OOP in JavaScript
// Prototypical Model
var UserPrototype = {};
UserPrototype.constructor = function(name)
{
this._name = name;
};
UserPrototype.getName = function()
{
return this._name;