Skip to content

Instantly share code, notes, and snippets.

View carlwiedemann's full-sized avatar

Carl Wiedemann carlwiedemann

View GitHub Profile
@carlwiedemann
carlwiedemann / az.php
Last active August 29, 2015 14:01
Given an alphabetic string via stdin, will return columnar index
<?php
define('ALPHA', 'abcdefghijklmnopqrstuvwxyz');
$pow = $sum = 0;
foreach (array_reverse(str_split(trim(file_get_contents('php://stdin', 'r')))) as $char) {
$sum += pow(strlen(ALPHA), $pow++) * (strpos(ALPHA, strtolower($char)) + 1);
}
<?php
function _dd($var) {
file_put_contents('/tmp/drupal_debug.txt', print_r($var, 1) . PHP_EOL , FILE_APPEND);
}

Keybase proof

I hereby claim:

  • I am c4rl on github.
  • I am c4rl (https://keybase.io/c4rl) on keybase.
  • I have a public key whose fingerprint is 71C9 F6AD 96D4 B203 014A 8574 67EA 2384 6CC2 4F46

To claim this, I am signing this object:

s = 0
1000.times {|i| s += i % 3 == 0 || i % 5 == 0 ? i : 0 }
puts s
s = 0
# First two Fibbonacci terms
f_last = 1
f = 1
while f < 4 * 10**6
# Sum evens
s += f % 2 == 0 ? f : 0
@carlwiedemann
carlwiedemann / gist:e17c4b1aad44a762d07d
Last active August 29, 2015 14:08
psuedo bin code yo
START
id keyword
--------------
123 acid and base
456 acid and bases
567 acids and bases
890 koalas
END
results =
{
'123' => [
1,
2,
3
],
'234' => [
1,
2
window['optimizely'].data.experiments.keys().forEach(function(key){
window['optimizely'].push(["activate", key]);
});
/**
* Reverts feature by name. Apparently it's not a thing. Let's make it a thing.
*
* @param string $name
* Machine name of the feature to revert.
*/
function _foobar_revert_feature($name) {
$feature = features_load_feature($name, TRUE);
$components = array();
foreach (array_keys($feature->info['features']) as $component) {
<?php
class Employee {
private $type;
const BASE_SALARY = 500;
function __construct(EmployeeType $type) {
$this->type = $type;