Skip to content

Instantly share code, notes, and snippets.

View sawant's full-sized avatar
🏠
Working from home

Sawant Shah sawant

🏠
Working from home
View GitHub Profile
@sawant
sawant / homebrew old version.txt
Last active March 16, 2024 05:35
Install older version of Formula in Homebrew
[From: http://hanxue-it.blogspot.com/2018/08/macos-homebrew-installing-older-version-of-software.html - just created a copy to keep it for long term]
Homebrew always wants to install the latest version of the Formula (software). This is by design, because every time there is an update to a formula, it wants to be tested against all the other formulas that it depends on. Mixing new and old versions of software is a recipe for incompatibility disaster.
But sometimes there are situations where you need an older version of software. In my specific case, Yarn was compiled against an older version of icu4c, and I want that older version instead of recompiling Yarn.
$ yarn install
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.61.dylib
Referenced from: /usr/local/bin/node
// Bonfire: Where do I belong
// Author: @sawant
// Challenge: http://www.freecodecamp.com/challenges/bonfire-where-do-i-belong?solution=function%20where(arr%2C%20num)%20%7B%0A%20%20%2F%2F%20Find%20my%20place%20in%20this%20sorted%20array.%0A%20%20arr.push(num)%3B%0A%20%20return%20arr.sort(function(a%2C%20b)%20%7Breturn%20a%20%3E%20b%3B%7D).indexOf(num)%3B%0A%7D%0A%0A%2F%2Fwhere(%5B40%2C%2060%5D%2C%2050)%3B%0Awhere(%5B5%2C%203%2C%2020%2C%203%5D%2C%205)%3B
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function where(arr, num) {
// Find my place in this sorted array.
arr.push(num);
return arr.sort(function(a, b) {return a > b;}).indexOf(num);
}
// Bonfire: Seek and Destroy
// Author: @sawant
// Challenge: http://www.freecodecamp.com/challenges/bonfire-seek-and-destroy?solution=function%20destroyer(arr)%20%7B%0A%20%20%2F%2F%20Remove%20all%20the%20values%0A%20%20var%20result%3B%20var%20args%20%3D%20%5B%5D%3B%0A%0A%20%20for%20(var%20i%20%3D%201%3B%20i%20%3C%20arguments.length%3B%20i%2B%2B)%20%7B%0A%20%20%20%20args.push(arguments%5Bi%5D)%3B%0A%20%20%7D%0A%0A%20%20result%20%3D%20arr.filter(function(val)%20%7B%0A%20%20%20%20return%20args.indexOf(val)%20%3D%3D%3D%20-1%3B%0A%20%20%7D)%3B%0A%20%20%0A%20%20return%20result%3B%0A%7D%0A%0Adestroyer(%5B1%2C%202%2C%203%2C%201%2C%202%2C%203%5D%2C%202%2C%203)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function destroyer(arr) {
// Remove all the values
var result; var args = [];
for (var i = 1; i < arguments.length; i++) {
// Bonfire: Falsy Bouncer
// Author: @sawant
// Challenge: http://www.freecodecamp.com/challenges/bonfire-falsy-bouncer?solution=function%20bouncer(arr)%20%7B%0A%20%20%2F%2F%20Don%27t%20show%20a%20false%20ID%20to%20this%20bouncer.%0A%20%20return%20arr.filter(function(val)%20%7B%0A%20%20%20%20return%20Boolean(val)%3B%0A%20%20%7D)%3B%0A%7D%0A%0Abouncer(%5B7%2C%20%22ate%22%2C%20%22%22%2C%20false%2C%209%5D)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function bouncer(arr) {
// Don't show a false ID to this bouncer.
return arr.filter(function(val) {
return Boolean(val);
});
// Bonfire: Mutations
// Author: @sawant
// Challenge: http://www.freecodecamp.com/challenges/bonfire-mutations?solution=function%20mutation(arr)%20%7B%0A%20%20for%20(var%20i%20%3D%200%3B%20i%20%3C%20arr%5B1%5D.length%3B%20i%2B%2B)%20%7B%0A%20%20%20%20if%20(%20arr%5B0%5D.toLowerCase().indexOf(%20arr%5B1%5D%5Bi%5D.toLowerCase()%20)%20%3D%3D%3D%20-1%20)%20return%20false%3B%0A%20%20%7D%0A%20%20%0A%20%20return%20true%3B%0A%7D%0A%0Amutation(%5B%22hello%22%2C%20%22hey%22%5D)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function mutation(arr) {
for (var i = 0; i < arr[1].length; i++) {
if ( arr[0].toLowerCase().indexOf( arr[1][i].toLowerCase() ) === -1 ) return false;
}
// Bonfire: Chunky Monkey
// Author: @sawant
// Challenge: http://www.freecodecamp.com/challenges/bonfire-chunky-monkey?solution=function%20chunk(arr%2C%20size)%20%7B%0A%20%20%2F%2F%20Break%20it%20up.%0A%20%20var%20result%20%3D%20%5B%5D%3B%0A%20%20for%20(var%20i%20%3D%200%3B%20i%20%3C%20arr.length%2Fsize%3B%20i%2B%2B)%20%7B%0A%20%20%20%20result.push(%20arr.slice(%20i%20*%20size%2C%20size%20*%20(i%2B1)%20)%20)%3B%0A%20%20%7D%0A%0A%20%20return%20result%3B%0A%7D%0A%0Achunk(%5B%22a%22%2C%20%22b%22%2C%20%22c%22%2C%20%22d%22%5D%2C%202)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function chunk(arr, size) {
// Break it up.
var result = [];
for (var i = 0; i < arr.length/size; i++) {
result.push( arr.slice( i * size, size * (i+1) ) );
// Bonfire: Truncate a string
// Author: @sawant
// Challenge: http://www.freecodecamp.com/challenges/bonfire-truncate-a-string?solution=function%20truncate(str%2C%20num)%20%7B%0A%20%20%2F%2F%20Clear%20out%20that%20junk%20in%20your%20trunk%0A%20%20return%20num%20%3C%20str.length%20%3F%20str.slice(0%2C%20num%20%3C%203%20%3F%20num%20%3A%20num%20-%203)%20%2B%20%22...%22%20%3A%20str%3B%0A%7D%0A%0Atruncate(%22A-tisket%20a-tasket%20A%20green%20and%20yellow%20basket%22%2C%2011)%3B
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function truncate(str, num) {
// Clear out that junk in your trunk
return num < str.length ? str.slice(0, num < 3 ? num : num - 3) + "..." : str;
}
// Bonfire: Repeat a string repeat a string
// Author: @sawant
// Challenge: http://www.freecodecamp.com/challenges/bonfire-repeat-a-string-repeat-a-string?solution=function%20repeat(str%2C%20num)%20%7B%0A%20%20%2F%2F%20repeat%20after%20me%0A%20%20return%20num%20%3E%200%20%3F%20str.repeat(num)%20%3A%20%22%22%3B%0A%7D%0A%0Arepeat(%22abc%22%2C%203)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function repeat(str, num) {
// repeat after me
return num > 0 ? str.repeat(num) : "";
}
// Bonfire: Confirm the Ending
// Author: @sawant
// Challenge: http://www.freecodecamp.com/challenges/bonfire-confirm-the-ending?solution=function%20end(str%2C%20target)%20%7B%0A%20%20%2F%2F%20%22Never%20give%20up%20and%20good%20luck%20will%20find%20you.%22%0A%20%20%2F%2F%20--%20Falcor%0A%20%20return%20str.substr(-target.length)%20%3D%3D%3D%20target%3B%0A%7D%0A%0Aend(%22Bastian%22%2C%20%22n%22)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function end(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
return str.substr(-target.length) === target;
}
<?php
function omit_twitter_script($provider, $url, $args) {
//get the hostname of the oEmbed endpoint provider being called
$host = parse_url($provider, PHP_URL_HOST);
//check to see that hostname is twitter.com
if (strpos($host, 'twitter.com') !== false) {
//adding ?omit_script=true to oEmbed endpoint call stops the returned HTML from containing widgets.js
$provider = add_query_arg('omit_script', 'true', $provider);
}
//return the $provider URL so the oEmbed can be fetched