const ITEM_COUNT = 100
let visibleItems = []
for (let i = 0; i < ITEM_COUNT; ++i) {
visibleItems.push(false)
}
function showItem(index) {
visibleItems = []
for (let i = 0; i < ITEM_COUNT; ++i) {
visibleItems.push(false)
}
visibleItems[index] = true
}
It was more or less like this. The guy had a collection of React components and wanted to show only one of them at a time. Instead of storing the index of the component to show at the moment, he decided that a boolean array would work much better. O(n) in runtime and space and null readability just because.
function getJSType(cppType: string) {
let typeMap = new Map<string, string>([
["Bool", "boolean"],
["Int32", "number"],
["UInt32", "number"],
["Int64", "number"],
["UInt64", "number"],
["Double", "number"],
["String", "string"],
["Object", "any"]
]);
if (typeMap.get(cppType) === undefined) {
console.error("Invalid type in getJavascriptType: " + cppType);
process.exit(1);
}
return typeMap.get(cppType);
}
$(".alarmBell").on("click", () => {
let icon = $(".alarm-bell__icon")
icon.attr('data', icon.attr('data') == 'images/icon/alarm-bell.svg' ? 'images/icon/alarm-bell-filled-new.svg' : 'images/icon/alarm-bell.svg');
// $(".alarm-bell__icon").attr('data', function (index, data) {
// if (data == 'images/icon/alarm-bell-filled-new.svg') {
// return 'images/icon/alarm-bell.svg';
// } else if (data == 'images/icon/alarm-bell.svg') {
// return 'images/icon/alarm-bell-filled-new.svg';
// } else {
// return 'images/icon/alarm-bell.svg';
// }
// });
});
...after yet another icons change request
<?php
$payload = '{ "products": [';
foreach ($products as $product) {
$payload .= $product->toJson() . ',';
}
$payload = substr($payload, 0, \strlen($payload) - 1);
$payload .= ']}';
$command = 'curl -X GET -H "application/json" -H "X-Api-Key: '.$key.'" https://some-api.com/resource';
exec($command, $output);
$array = json_decode($output[0], true);
Using curl in PHP is boring. Let execute a command for
string date = user.RegistrationDate.ToShortDateString().ToString();
from itertools import combinations as comb
from functools import reduce
def all_arrangements(k):
m=k*(k+1)/2
m_bits_on=set([tuple(reduce(lambda x,y:x[:y]+[1]+x[y+1:],c,[0]*(2*m+1))) for c in comb(range(2*m+1),m)])
return set([tuple(sorted(filter(lambda i:i>0,reduce(lambda x,y: x+[y] if y==0 else x[:-1]+[x[-1]+1,],p,[0])))) for p in m_bits_on])
Returns all arrangements in the Bulgarian solitaire game with k piles https://en.wikipedia.org/wiki/Bulgarian_solitaire
in_array($this->market, ["ru"])
There is an old mysterious legend, which says that those conditions are lightening fast which are using in_array($source, ["target"]) instead of just "==". Is says always that probably you never do code refactoring, and keep all shit alive
self.isOptionsVisible = ko.computed(function() {
if((self.type() == 'select') || (self.type() == 'multiselect') || (self.type() == 'radio') || (self.type() == 'checkbox') || (self.type() == 'upload')) {
return true;
}
return false;
}, this);
self.isNameVisible = ko.computed(function() {
if((self.type() == 'text') || (self.type() == 'textarea') || (self.type() == 'select') || (self.type() == 'multiselect') || (self.type() == 'radio') || (self.type() == 'checkbox') || (self.type() == 'upload')) {
return true;
}
return false;
}, this);
self.isBeforeAfterImagesVisible = ko.computed(function() {
if((self.type() == 'text') || (self.type() == 'textarea') || (self.type() == 'select') || (self.type() == 'multiselect') || (self.type() == 'radio') || (self.type() == 'checkbox') || (self.type() == 'upload')) {
return true;
}
return false;
}, this);
self.isTooltipVisible = ko.computed(function() {
if((self.type() == 'text') || (self.type() == 'textarea') || (self.type() == 'select') || (self.type() == 'multiselect') || (self.type() == 'radio') || (self.type() == 'checkbox') || (self.type() == 'upload')) {
return true;
}
return false;
}, this);
self.isLabelVisible = ko.computed(function() {
if((self.type() == 'text') || (self.type() == 'textarea') || (self.type() == 'select') || (self.type() == 'multiselect') || (self.type() == 'radio') || (self.type() == 'checkbox') || (self.type() == 'upload') || (self.type() == 'info')) {
return true;
}
return false;
}, this);
self.isClassVisible = ko.computed(function() {
if((self.type() == 'text') || (self.type() == 'textarea') || (self.type() == 'select') || (self.type() == 'multiselect') || (self.type() == 'radio') || (self.type() == 'checkbox') || (self.type() == 'upload')) {
return true;
}
return false;
}, this);
self.isStyleVisible = ko.computed(function() {
if((self.type() == 'text') || (self.type() == 'textarea') || (self.type() == 'select') || (self.type() == 'multiselect') || (self.type() == 'radio') || (self.type() == 'checkbox') || (self.type() == 'upload')) {
return true;
}
return false;
}, this);
object orientation overrated. let's check the fields in several places ...
doit({txs, [Tx]}) ->
X = tx_pool_feeder:absorb(Tx),
Y = case X of
ok -> hash:doit(testnet_sign:data(Tx));
_ -> <<"error">>
end,
{ok, Y};
In my opinion api response should be as confusing as possible. This method is used for sending tx into Amoveo blockchain. It returns ["ok",
$net_price = "var net_price = " . json_encode($net_price) . ";";
This is a Javascript variable being created inside of a PHP string.
if ((bool)greenButton.IsChecked)
{
CurrentColor = Color.FromArgb(0xFF, 0x00, 0xCC, 0x00);
}
else if ((bool)greyButton.IsChecked)
{
CurrentColor = Color.FromArgb(0xFF, 0x79, 0x79, 0x79);
}
foreach (var item in ItemsList.Items)
{
if ((grid.Background as SolidColorBrush).Color == CurrentColor)
{
selectedItems.Add(item);
}
}
{k: v for d in [{ key: { 0: x[0], } for key in x["name"] } for x in items] for k, v in d.items()}
$config = Config::getConfig('common');
$contract_carriers = $config[$market . "_" . $clearing . '_contract_carriers']; // f**ing php array
$interline_carriers = $config[$market . "_" . $clearing . '_interline_carriers']; // another f**ing array
// $marketing_carriers - is also array
$sets = [];
foreach ($marketing_carriers as $mc) {
$sets[] = array_unique(array_intersect(
array_merge(
[$mc],
array_intersect(
isset(self::$interlines[$mc]) ? self::$interlines[$mc] : [],
array_merge(
$marketing_carriers,
$interline_carriers
)
)
),
$contract_carriers
));
}
$_POST = $this->db->mres($_POST);
$_SESSION['post'] = $_POST;
$sql = "SELECT id, documento, nombre1, nombre2, apellido1, apellido2 "
. "FROM usuarios "
. "WHERE " .
"REPLACE(" .
"REPLACE(" .
"REPLACE(" .
"REPLACE(telefono,' ','')," .
"'(','')," .
"')','')," .
"'-','') LIKE '%{$searchTel}'";