Skip to content

Instantly share code, notes, and snippets.

View tim-field's full-sized avatar
💭
🤙

Tim Field tim-field

💭
🤙
  • Dunedin New Zealand
View GitHub Profile
@goldhand
goldhand / immutableMove.js
Created March 8, 2017 00:52
Immutable move item in an array
/**
* Immutable move item
*/
const move = (arr, from, to) => {
const clone = [...arr];
Array.prototype.splice.call(clone, to, 0,
Array.prototype.splice.call(clone, from, 1)[0]
);
return clone;
};
@InfoSec812
InfoSec812 / jsonb_patch.sql
Last active June 26, 2024 11:02
Pure PostgreSQL implementation of JSONPatch
!!
!! Implementation of JSONPatch (http://jsonpatch.com/) using PostgreSQL >= 9.5
!!
CREATE OR REPLACE FUNCTION jsonb_copy(JSONB, TEXT[], TEXT[]) RETURNS JSONB AS $$
DECLARE
retval ALIAS FOR $1;
src_path ALIAS FOR $2;
dst_path ALIAS FOR $3;
tmp_value JSONB;
@adamloving
adamloving / react-numeral-input.jsx
Created June 24, 2016 23:53
React based HTML input for dollars that disallows decimals and inserts commas.
class NumericInput extends React.Component {
constructor(props = {}) {
super(props)
this.state = {
value: numeral(props.value).format('0,0')
}
}
onChange(e) {
var number = numeral().unformat(e.target.value)

Principles of Adult Behavior

  1. Be patient. No matter what.
  2. Don’t badmouth: Assign responsibility, not blame. Say nothing of another you wouldn’t say to him.
  3. Never assume the motives of others are, to them, less noble than yours are to you.
  4. Expand your sense of the possible.
  5. Don’t trouble yourself with matters you truly cannot change.
  6. Expect no more of anyone than you can deliver yourself.
  7. Tolerate ambiguity.
  8. Laugh at yourself frequently.
@gwparikh
gwparikh / On-the-fly video converting and streaming with ffmpeg and netcat.md
Last active May 10, 2021 20:21
Been wanting to figure out how to do this for a while, ended up being pretty easy once I spent a few years in the shell with ffmpeg...

On-the-fly Video Converting and End-to-End Streaming With FFMPEG and netcat

Transcoding & Sending:

ssh -R <port>:localhost:<port> <host_with_content> ffmpeg -i <input_file> -c:v libx264 -q 1 -c:a libmp3lame -f avi pipe:1 | nc localhost <port>

Playing:

@karanlyons
karanlyons / partial_range_update.sql
Last active September 16, 2022 15:11
Postgres: Update only portion of range, preserving other half and bounds.
UPDATE <TABLE> SET
<COLUMN>=<RANGE_TYPE>(
lower(<COLUMN>), -- Swap out for actual value
upper(<COLUMN>), -- Swap out for actual value
concat(
CASE WHEN lower_inc(<COLUMN>) THEN '[' ELSE '(' END,
CASE WHEN upper_inc(<COLUMN>) THEN ']' ELSE ')' END
)
)
WHERE <CONDITION>;
@Rarst
Rarst / composer.json
Last active January 27, 2023 12:40
Test project for WordPress stack via Composer
{
"name" : "rarst/install-test",
"description" : "Test project for WordPress stack via Composer",
"authors" : [
{
"name" : "Andrey Savchenko",
"homepage": "http://www.Rarst.net/"
}
],
"type" : "project",