Skip to content

Instantly share code, notes, and snippets.

View aknosis's full-sized avatar
🏔️
Working Remotely

Paul Giberson aknosis

🏔️
Working Remotely
View GitHub Profile
@brandonsavage
brandonsavage / gist:801f921012d553b1a95d
Created January 7, 2015 15:03
My favorite function in PHP...
public function configure(array $values = array())
{
foreach ($values as $key => $value) {
if (property_exists($this, $key)) {
$this->$key = $value;
}
}
return $this;
}
anonymous
anonymous / mfp.sh
Created February 22, 2016 03:23
curl \
-O http://datashat.net/music_for_programming_0-manifesto.mp3 \
-O http://datashat.net/music_for_programming_1-datassette.mp3 \
-O http://datashat.net/music_for_programming_2-sunjammer.mp3 \
-O http://datashat.net/music_for_programming_3-datassette.mp3 \
-O http://datashat.net/music_for_programming_4-com_truise.mp3 \
-O http://datashat.net/music_for_programming_5-abe_mangger.mp3 \
-O http://datashat.net/music_for_programming_6-gods_of_the_new_age.mp3 \
-O http://datashat.net/music_for_programming_7-tahlhoff_garten_and_untitled.mp3 \
-O http://datashat.net/music_for_programming_8-connectedness_locus.mp3 \
@gf3
gf3 / ago.js
Created June 2, 2011 18:43
Super small relative dates
module.exports = (function(){
const MS =
{ seconds: 1000
, minutes: 60 * 1000
, hours: 60 * 60 * 1000
, days: 24 * 60 * 60 * 1000
, weeks: 7 * 24 * 60 * 60 * 1000
, months: 30 * 7 * 24 * 60 * 60 * 1000
, years: 365 * 24 * 60 * 60 * 1000 }
@coderabbi
coderabbi / post-merge
Created December 18, 2017 11:27
'composer install' git post-merge hook
# .git/hooks/post-merge
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
composer_install_on_changed_lockfile() {
echo "$changed_files" | grep --quiet "composer.lock" &&
echo "Changes to 'composer.lock' detected; running 'composer install'." &&
composer install
}
@clauddiu
clauddiu / eloquent.php
Created December 7, 2012 15:50
Using Eloquent outside of Laravel 4 this extends gist https://gist.github.com/4107178
<?php
require 'vendor/autoload.php';
$resolver = new Illuminate\Database\ConnectionResolver;
$resolver->setDefaultConnection('default');
$factory = new Illuminate\Database\Connectors\ConnectionFactory;
$connection = $factory->make(array(
'host' => 'localhost',
'database' => 'database',
@maxrice
maxrice / us-state-names-abbrevs.php
Created May 23, 2012 18:32
US State Names & Abbreviations as PHP Arrays
<?php
/* From https://www.usps.com/send/official-abbreviations.htm */
$us_state_abbrevs_names = array(
'AL'=>'ALABAMA',
'AK'=>'ALASKA',
'AS'=>'AMERICAN SAMOA',
'AZ'=>'ARIZONA',
'AR'=>'ARKANSAS',
@ravibhure
ravibhure / git_rebase.md
Last active April 3, 2024 08:38
Git rebase from remote fork repo

In your local clone of your forked repository, you can add the original GitHub repository as a "remote". ("Remotes" are like nicknames for the URLs of repositories - origin is one, for example.) Then you can fetch all the branches from that upstream repository, and rebase your work to continue working on the upstream version. In terms of commands that might look like:

Add the remote, call it "upstream":

git remote add upstream https://github.com/whoever/whatever.git

Fetch all the branches of that remote into remote-tracking branches, such as upstream/master:

git fetch upstream

Make it real

Ideas are cheap. Make a prototype, sketch a CLI session, draw a wireframe. Discuss around concrete examples, not hand-waving abstractions. Don't say you did something, provide a URL that proves it.

Ship it

Nothing is real until it's being used by a real user. This doesn't mean you make a prototype in the morning and blog about it in the evening. It means you find one person you believe your product will help and try to get them to use it.

Do it with style

@jwage
jwage / SplClassLoader.php
Last active April 9, 2024 21:04
Add MIT license.
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
@nikic
nikic / objects_arrays.md
Last active April 12, 2024 17:05
Post explaining why objects often use less memory than arrays (in PHP)

Why objects (usually) use less memory than arrays in PHP

This is just a small post in response to [this tweet][tweet] by Julien Pauli (who by the way is the release manager for PHP 5.5). In the tweet he claims that objects use more memory than arrays in PHP. Even though it can be like that, it's not true in most cases. (Note: This only applies to PHP 5.4 or newer.)

The reason why it's easy to assume that objects are larger than arrays is because objects can be seen as an array of properties and a bit of additional information (like the class it belongs to). And as array + additional info > array it obviously follows that objects are larger. The thing is that in most cases PHP can optimize the array part of it away. So how does that work?

The key here is that objects usually have a predefined set of keys, whereas arrays don't: