Skip to content

Instantly share code, notes, and snippets.

@zachsa
zachsa / cURL examples
Created July 17, 2018 10:19
A number of hard to remember cURL commands
# cURL with attachments
curl \
-i \
-u <username>:<pswd> \
-H "Content-Type: image/jpeg" \
-X PUT \
—data-binary @imageHouse_.jpg \
"<url>"
@zachsa
zachsa / CSV reader
Created August 28, 2018 19:23
Iterative CSV reader that allows unescaped newline chars in quoted fields
var fs = require('fs')
var CsvReadableStream = require('csv-reader')
const quotedRows = [8, 10]
var i = 0
const redactQuestions = [
"Home Phone:xxx-xxx-xxxx",
"Work Phone:xxx-xxx-xxxx",
"Cell Phone:xxx-xxx-xxxx",
using System;
using Microsoft.VisualBasic.FileIO;
using System.IO;
namespace consoleTester
{
public class Program
{
private static readonly string filename = "sfcts_response_attach_data20180717.csv";
var accountSid = '...'; // Your Account SID from www.twilio.com/console
var authToken = '...'; // Your Auth Token from www.twilio.com/console
var twilio = require('twilio');
/**
* var client = new twilio.RestClient(accountSid, authToken);
*
* client.messages.create({
* body: 'Hello from Node',
* to: '+12345678901', // Text this number
Create a folder with 2 files:
1. index.js
2. index.html
Then navigate to the root of the folder and start with this command: `node index.js`
=====================================================
@zachsa
zachsa / sorted-array.js
Created May 1, 2019 18:55
Example of Array constructor that supports sorted insertion (JavaScript)
function SortedArray(...args) { return [...args].sort() }
SortedArray.prototype = Array.prototype
SortedArray.prototype.insert = function(item) {
function getLocation(item, start, end) {
// Get start, end, position
start = start || 0
end = end || this.length
const p = parseInt(start + (end - start) / 2, 10)
// Finally return position
@zachsa
zachsa / Simple C Webserver
Last active May 8, 2019 20:32
Looking at creating a webserver in C
// https://dev-notes.eu/2018/06/http-server-in-c/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <netdb.h>
#include <arpa/inet.h>
@zachsa
zachsa / bigquery-median.sql
Created June 24, 2019 01:20
Noteworthy BigQuery SQL for calculating MEDIAN
create temp function MEDIAN(num_arr array<float64>)
returns float64 as (
( select avg(num)
from (
select
row_number() over (order by num) -1 as rn,
num
from unnest(num_arr) num
)
where
@zachsa
zachsa / chain.js
Created July 2, 2019 10:33
Interesting functional approach to dot-chaining
const chain = (...fns) => arg => fns.reduce((prev, fn) => fn(prev), arg)
const odds = array => array.filter(x => x % 2 === 0)
const double = array => array.map(x => x + x)
const result = chain(odds, double)([1,2,3,4,5,6,7,8])
console.log(result)
@zachsa
zachsa / redux-poc.jsx
Created July 5, 2019 09:38
The most simple example of Redux in React that I can think of. Specifically.. shows how to use connect()
import React from 'react'
import { render } from "react-dom"
import { createStore } from "redux"
import { Provider, connect } from "react-redux"
import { mergeLeft } from "ramda";
// Setup Redux store
const initialState = { count: 0, other: 3, something: 4 }
const reducer = (state = initialState) => mergeLeft({count: state.count + 1}, state)
const store = createStore(reducer)