Skip to content

Instantly share code, notes, and snippets.

@smailliwcs
smailliwcs / dog.js
Created September 22, 2020 15:24
Object-oriented JavaScript
if (typeof Object.create !== "function") {
Object.create = function (proto) {
function Type() { }
Type.prototype = proto;
return new Type();
};
}
function Animal(name) {
var self = this;
@smailliwcs
smailliwcs / underscore.patch
Created September 22, 2020 15:24
Fixing Underscore.php
@@ -176,7 +176,7 @@ all: Wrap return value
$__ = new self;
if(!is_null($iterator)) $collection = $__->map($collection, $iterator);
$collection = (array) $collection;
- if(count($collection) === 0) return true;
+ if(count($collection) === 0) return self::_wrap(true);
return self::_wrap(is_bool(array_search(false, $collection, false)));
}
@@ -191,8 +191,8 @@ filter: Pass key to iterator
@smailliwcs
smailliwcs / output.txt
Created September 22, 2020 15:24
Underscore.php mixin: sort
Array
(
[0] => 5
[1] => 1
[2] => 3
[3] => 0
[4] => 6
[5] => 8
[6] => 4
[7] => 9
@smailliwcs
smailliwcs / multisort.php
Created September 22, 2020 15:24
Underscore.php mixin: multisort
<?php
__()->mixin([
"reindex" => function ($items, $indices) {
return __($indices)->map(function ($index) use ($items) { return $items[$index]; });
},
"multisort" => function ($items, $keys) {
if (count($items) <= 1) {
return $items;
}
@smailliwcs
smailliwcs / output.png
Last active September 22, 2020 15:28
GIMP script: script-fu-highlight
output.png
@smailliwcs
smailliwcs / gradient.plt
Last active September 22, 2020 15:29
Gradients in gnuplot
set terminal png size 640,480
set output 'gradient.png'
set xrange [-5:5]
set yrange [-5:5]
set cbrange [0:1]
unset colorbox
unset key
set palette gray negative
set object 1 rectangle from 1,-10 to 10,10 behind fillcolor rgb 'black' fillstyle noborder
plot '< python gradient.py -x -1 1 -10 10 64' with image
@smailliwcs
smailliwcs / App.config
Created September 22, 2020 15:24
Custom configuration sections
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="presidents1" type="System.Configuration.NameValueSectionHandler" />
<section name="presidents2" type="CustomConfig.PresidentListSection, Custom Config" />
</configSections>
<presidents1>
<add key="1" value="George Washington" />
<add key="2" value="John Adams" />
<add key="3" value="Thomas Jefferson" />
@smailliwcs
smailliwcs / App.config
Created September 22, 2020 15:24
NoSleep
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="Distance" value="10" />
<add key="Timeout" value="1:00" />
</appSettings>
</configuration>
@smailliwcs
smailliwcs / proxy.php
Created September 22, 2020 15:24
Simple PHP proxy
<?php
function download($url) {
$curl = curl_init($url);
curl_setopt_array($curl, [
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_RETURNTRANSFER => true
]);
$data = curl_exec($curl);
curl_close($curl);
return $data;
@smailliwcs
smailliwcs / hg-cvs.sh
Created September 22, 2020 15:24
Mercurial and upstream CVS with MQ
# Set up repo
cvs checkout repo
cd repo
hg init
>> .hgignore echo syntax: glob
>> .hgignore echo CVS/*
>> .hgignore echo .cvsignore
# Consult .cvsignore files
hg addremove
# Verify pending changes