Skip to content

Instantly share code, notes, and snippets.

View ntilwalli's full-sized avatar

Nikhil Tilwalli ntilwalli

View GitHub Profile
@ntilwalli
ntilwalli / gist:c2a412a2b4e1d41078a54d6844f32a25
Created September 23, 2019 22:01
Bash script to extract chromedriver version based on installed google-chrome-stable
function extract_chromedriver_version(){
local regex='Google Chrome ([0-9]{1,4}.[0-9]{1,4}.[0-9]{1,4}).[0-9]*'
local mystring1=$(google-chrome-stable --version)
[[ $mystring1 =~ $regex ]]
local base_ver=${BASH_REMATCH[1]}
local filename="LATEST_RELEASE_${base_ver}"
local url="https://chromedriver.storage.googleapis.com/${filename}"
wget ${url}
local chromedriver_version=$(cat ${filename})
rm ${filename}
@ntilwalli
ntilwalli / preloading.exs
Last active March 24, 2018 19:13
Ecto preloading within transaction
# create table(:invites) do
# add :foo_id, references(:foo, on_delete: :delete_all), null: false
# add :to_id, references(:users, on_delete: :delete_all), null: true
# add :status, :string
# end
# create table(:holders) do
# add :foo_id, references(:foo, on_delete: :delete_all), null: false
# add :user_id, references(:users, on_delete: :delete_all), null: true
# add :invite_id, referendes(:invites, on_delete: :delete_all)
@ntilwalli
ntilwalli / clickElsewhereExample.txt
Created November 30, 2017 00:02
Click elsewhere with CycleJS
import FooComponent from './components/foo'
function globalUID() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
@ntilwalli
ntilwalli / hot_vs_cold.md
Last active October 4, 2017 14:56
Cold/Hot !== Unicast/Multicast

Hot/cold refers to whether a stream reference emits the same set of values to all subscribers...regardless of when they subscribe. Cold streams will emit the exact same data to all subscribers (the first subscriber and the last) no matter when they subscribe (xs.of('foo') is a cold stream). Hot streams will not necessarily emit the same data to later subscribers. They're live. Subscribing to a hot stream means you may have missed previous emissions (or what would have been previous emissions had there been subscribers) and those emissions cannot be recovered.

For example, a stream which emits the current unix time every second may have no subscribers, but it's still a hot stream because it had valid emissions before you subscribed... but you missed them...

In xstream where everything is multicast, what determines whether a stream is hot or cold (aka whether the stream may have had previous emissions that can't be recovered) is often whether there are existing subscribers to a stream reference. Th

@ntilwalli
ntilwalli / esnextbin.md
Last active November 18, 2016 20:15
esnextbin sketch
@ntilwalli
ntilwalli / esnextbin.md
Last active November 8, 2016 15:42
esnextbin sketch
@ntilwalli
ntilwalli / esnextbin.md
Last active November 8, 2016 15:23
esnextbin sketch
@ntilwalli
ntilwalli / combineObj.js
Created July 2, 2016 13:38
Equivalent to rx-combine-latest-obj for xstream
import xs from 'xstream'
export default function combineObj(obj) {
var sources = [];
var keys = [];
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
keys.push(key.replace(/\$$/, ''));
sources.push(obj[key]);
}
@ntilwalli
ntilwalli / nested.md
Last active March 8, 2016 20:23
Sketch of possible nested requests approach in CycleJS
function modifications(actions, fromHTTP$) {
  const secondaryResponsesMod$ = fromHTTP$
    .map(resp => function (state) {
      // compare response with the keys in state.get('secondaryResponseContainer')
      // and fill the value in appropriately, if all expected responses have come in, set inFlight to false
      return state.set(`inFlight`, false)
    })
}
@ntilwalli
ntilwalli / ColdToHotRxJS.md
Last active January 24, 2016 18:13
Going from Cold to Hot

###A Walkthrough of Observables, Subjects, Replay and Sharing Streams in RxJS

To properly understand observables in RxJS you need to understand cold vs. hot, subscription propagation and how subscription propagation is modified by Subjects.

####Cold vs. Hot