TV reality
22 Aug 2015
You can use methods like this to easily get which day of the week we it is now.
function isMonday() {
d = new Date().getDay();
return d === 1;
}
function isMondayOrSunday() {
d = new Date().getDay();
return d === 0 || d === 1;
}
but for the convenience and also not to have to remember where the week starts (it starts on Sunday with 0) you can use something like the following:
function getDayOfWeek() {
var d = new Date();
var weekday = new Array(7);
weekday[0] = "Sunday";
weekday[1] = "Monday";
weekday[2] = "Tuesday";
weekday[3] = "Wednesday";
weekday[4] = "Thursday";
weekday[5] = "Friday";
weekday[6] = "Saturday";
return weekday[d.getDay()];
}
Paired together with the previous post about obtaining any timezone for the date, you can use these methods for any timezone replacing the new Date() with the getGMTRelativeDate(GMT_offsetHours)
e.g.
function isMonday() {
d = getGMTRelativeDate(-5).getDay(); // for EST time
return d === 1;
}
A little something I wrote since I did not find anything that does that readily available. It looks solid but may contain bugs for corner cases or possibly other minor inconsistencies. For my needed timezones it seems to work fine.
/**
* Returns a Date object with the time setup for the desired remote timezone
* e.g.
* EST - UTC/GMT-5 --> getGMTRelativeDate(-5);
* EDT - UTC/GMT-4 --> getGMTRelativeDate(-4);
* PST - UTC/GMT-8 --> getGMTRelativeDate(-8);
* PDT - UTC/GMT-7 --> getGMTRelativeDate(-7);
* Rome - UTC/GMT+2 --> getGMTRelativeDate(2);
* Japan - UTC/GMT+9 --> getGMTRelativeDate(9);
* etc...
*/
function function getGMTRelativeDate(GMTOffset) {
var localDate = new Date();
offset = localDate.getTimezoneOffset();
LOCALOffset = (offset / -60)
tzDiff = LOCALOffset - GMTOffset;
localTime = new Date().getTime();
RemoteTime = localTime - (tzDiff * 3600 * 1000);
remoteDate = new Date(RemoteTime);
//log("Remote time = " + remoteDate.toLocaleString());
return remoteDate;
}
// To invoke just pass the desired diff with GMT
getGMTRelativeDate(-2);
Oneliner to speed up screenshot taking process.
adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > screenshot.png
Combined with the adb shell start command that launches intents and activities the process of taking screenshots can be completely automated.
Unlock the screen:
adb shell input keyevent 82
Power buttona
adb shell input keyevent 26
###TL;DR
add this to your rc file
[[ -s "$HOME/.gvm/scripts/gvm" ]] && source "$HOME/.gvm/scripts/gvm"
###The Details:
There is a wonderful tool to install and otherwise manage go versions gvm. It is very similar to nvm (node version manager)
To install gvm run:
$ bash < <(curl -s https://raw.github.com/moovweb/gvm/master/binscripts/gvm-installer)
if you are using zsh and ohmyzsh in particular, you need to add this to your rc file
[[ -s "$HOME/.gvm/scripts/gvm" ]] && source "$HOME/.gvm/scripts/gvm"
Then it is easy to install and use any version of go.
to list available go versions:
gvm listall
to install just use:
gvm install go1.4.2
currently most recent stable version of go.
You will get something like that:
➜ ~ gvm install go1.4.2
Downloading Go source...
Installing go1.4.2...
* Compiling...
➜ ~
to make it a default use this commands:
gvm use go1.4.2 --default
After running go use command you will have the $GOROOT added and the $PATH updated.
Go will reside in ~/.gvm/gos/go1.4.2 or a similar folder, depending on the version(s) you have installed.
Kudos to the author for making our lives easier!
Here’s the latest material colors as an XML resource.
You can use it by
<?xml version="1.0" encoding="utf-8"?>
<!--
Created by: inteist - max@inteist.com
@inteist on Github and Twitter
This resource is licensed under
Creative Commons Attribution 4.0 International License.
http://creativecommons.org/licenses/by/4.0/
-->
<resources>
<!--Red-->
<color name="material_red_50">#FFEBEE</color>
<color name="material_red_100">#FFCDD2</color>
<color name="material_red_200">#EF9A9A</color>
<color name="material_red_300">#E57373</color>
<color name="material_red_400">#EF5350</color>
<color name="material_red_500">#F44336</color>
<color name="material_red_600">#E53935</color>
<color name="material_red_700">#D32F2F</color>
<color name="material_red_800">#C62828</color>
<color name="material_red_900">#B71C1C</color>
<color name="material_red_A100">#FF8A80</color>
<color name="material_red_A200">#FF5252</color>
<color name="material_red_A400">#FF1744</color>
<color name="material_red_A700">#D50000</color>
<!--Pink-->
<color name="material_pink_50">#FCE4EC</color>
<color name="material_pink_100">#F8BBD0</color>
<color name="material_pink_200">#F48FB1</color>
<color name="material_pink_300">#F06292</color>
<color name="material_pink_400">#EC407A</color>
<color name="material_pink_500">#E91E63</color>
<color name="material_pink_600">#D81B60</color>
<color name="material_pink_700">#C2185B</color>
<color name="material_pink_800">#AD1457</color>
<color name="material_pink_900">#880E4F</color>
<color name="material_pink_A100">#FF80AB</color>
<color name="material_pink_A200">#FF4081</color>
<color name="material_pink_A400">#F50057</color>
<color name="material_pink_A700">#C51162</color>
<!--Purple-->
<color name="material_purple_50">#F3E5F5</color>
<color name="material_purple_100">#E1BEE7</color>
<color name="material_purple_200">#CE93D8</color>
<color name="material_purple_300">#BA68C8</color>
<color name="material_purple_400">#AB47BC</color>
<color name="material_purple_500">#9C27B0</color>
<color name="material_purple_600">#8E24AA</color>
<color name="material_purple_700">#7B1FA2</color>
<color name="material_purple_800">#6A1B9A</color>
<color name="material_purple_900">#4A148C</color>
<color name="material_purple_A100">#EA80FC</color>
<color name="material_purple_A200">#E040FB</color>
<color name="material_purple_A400">#D500F9</color>
<color name="material_purple_A700">#AA00FF</color>
<!--Deep Purple-->
<color name="material_deep_purple_50">#EDE7F6</color>
<color name="material_deep_purple_100">#D1C4E9</color>
<color name="material_deep_purple_200">#B39DDB</color>
<color name="material_deep_purple_300">#9575CD</color>
<color name="material_deep_purple_400">#7E57C2</color>
<color name="material_deep_purple_500">#673AB7</color>
<color name="material_deep_purple_600">#5E35B1</color>
<color name="material_deep_purple_700">#512DA8</color>
<color name="material_deep_purple_800">#4527A0</color>
<color name="material_deep_purple_900">#311B92</color>
<color name="material_deep_purple_A100">#B388FF</color>
<color name="material_deep_purple_A200">#7C4DFF</color>
<color name="material_deep_purple_A400">#651FFF</color>
<color name="material_deep_purple_A700">#6200EA</color>
<!--Indigo-->
<color name="material_indigo_50">#E8EAF6</color>
<color name="material_indigo_100">#C5CAE9</color>
<color name="material_indigo_200">#9FA8DA</color>
<color name="material_indigo_300">#7986CB</color>
<color name="material_indigo_400">#5C6BC0</color>
<color name="material_indigo_500">#3F51B5</color>
<color name="material_indigo_600">#3949AB</color>
<color name="material_indigo_700">#303F9F</color>
<color name="material_indigo_800">#283593</color>
<color name="material_indigo_900">#1A237E</color>
<color name="material_indigo_A100">#8C9EFF</color>
<color name="material_indigo_A200">#536DFE</color>
<color name="material_indigo_A400">#3D5AFE</color>
<color name="material_indigo_A700">#304FFE</color>
<!--Blue-->
<color name="material_blue_50">#E3F2FD</color>
<color name="material_blue_100">#BBDEFB</color>
<color name="material_blue_200">#90CAF9</color>
<color name="material_blue_300">#64B5F6</color>
<color name="material_blue_400">#42A5F5</color>
<color name="material_blue_500">#2196F3</color>
<color name="material_blue_600">#1E88E5</color>
<color name="material_blue_700">#1976D2</color>
<color name="material_blue_800">#1565C0</color>
<color name="material_blue_900">#0D47A1</color>
<color name="material_blue_A100">#82B1FF</color>
<color name="material_blue_A200">#448AFF</color>
<color name="material_blue_A400">#2979FF</color>
<color name="material_blue_A700">#2962FF</color>
<!--Light Blue-->
<color name="material_light_blue_50">#E1F5FE</color>
<color name="material_light_blue_100">#B3E5FC</color>
<color name="material_light_blue_200">#81D4FA</color>
<color name="material_light_blue_300">#4FC3F7</color>
<color name="material_light_blue_400">#29B6F6</color>
<color name="material_light_blue_500">#03A9F4</color>
<color name="material_light_blue_600">#039BE5</color>
<color name="material_light_blue_700">#0288D1</color>
<color name="material_light_blue_800">#0277BD</color>
<color name="material_light_blue_900">#01579B</color>
<color name="material_light_blue_A100">#80D8FF</color>
<color name="material_light_blue_A200">#40C4FF</color>
<color name="material_light_blue_A400">#00B0FF</color>
<color name="material_light_blue_A700">#0091EA</color>
<!--Cyan-->
<color name="material_cyan_50">#E0F7FA</color>
<color name="material_cyan_100">#B2EBF2</color>
<color name="material_cyan_200">#80DEEA</color>
<color name="material_cyan_300">#4DD0E1</color>
<color name="material_cyan_400">#26C6DA</color>
<color name="material_cyan_500">#00BCD4</color>
<color name="material_cyan_600">#00ACC1</color>
<color name="material_cyan_700">#0097A7</color>
<color name="material_cyan_800">#00838F</color>
<color name="material_cyan_900">#006064</color>
<color name="material_cyan_A100">#84FFFF</color>
<color name="material_cyan_A200">#18FFFF</color>
<color name="material_cyan_A400">#00E5FF</color>
<color name="material_cyan_A700">#00B8D4</color>
<!--Teal-->
<color name="material_teal_50">#E0F2F1</color>
<color name="material_teal_100">#B2DFDB</color>
<color name="material_teal_200">#80CBC4</color>
<color name="material_teal_300">#4DB6AC</color>
<color name="material_teal_400">#26A69A</color>
<color name="material_teal_500">#009688</color>
<color name="material_teal_600">#00897B</color>
<color name="material_teal_700">#00796B</color>
<color name="material_teal_800">#00695C</color>
<color name="material_teal_900">#004D40</color>
<color name="material_teal_A100">#A7FFEB</color>
<color name="material_teal_A200">#64FFDA</color>
<color name="material_teal_A400">#1DE9B6</color>
<color name="material_teal_A700">#00BFA5</color>
<!-- Green -->
<color name="material_green_50">#E8F5E9</color>
<color name="material_green_100">#C8E6C9</color>
<color name="material_green_200">#A5D6A7</color>
<color name="material_green_300">#81C784</color>
<color name="material_green_400">#66BB6A</color>
<color name="material_green_500">#4CAF50</color>
<color name="material_green_600">#43A047</color>
<color name="material_green_700">#388E3C</color>
<color name="material_green_800">#2E7D32</color>
<color name="material_green_900">#1B5E20</color>
<color name="material_green_A100">#B9F6CA</color>
<color name="material_green_A200">#69F0AE</color>
<color name="material_green_A400">#00E676</color>
<color name="material_green_A700">#00C853</color>
<!-- Light Green -->
<color name="material_light_green_50">#F1F8E9</color>
<color name="material_light_green_100">#DCEDC8</color>
<color name="material_light_green_200">#C5E1A5</color>
<color name="material_light_green_300">#AED581</color>
<color name="material_light_green_400">#9CCC65</color>
<color name="material_light_green_500">#8BC34A</color>
<color name="material_light_green_600">#7CB342</color>
<color name="material_light_green_700">#689F38</color>
<color name="material_light_green_800">#558B2F</color>
<color name="material_light_green_900">#33691E</color>
<color name="material_light_green_A100">#CCFF90</color>
<color name="material_light_green_A200">#B2FF59</color>
<color name="material_light_green_A400">#76FF03</color>
<color name="material_light_green_A700">#64DD17</color>
<!--Lime-->
<color name="material_lime_50">#F9FBE7</color>
<color name="material_lime_100">#F0F4C3</color>
<color name="material_lime_200">#E6EE9C</color>
<color name="material_lime_300">#DCE775</color>
<color name="material_lime_400">#D4E157</color>
<color name="material_lime_500">#CDDC39</color>
<color name="material_lime_600">#C0CA33</color>
<color name="material_lime_700">#AFB42B</color>
<color name="material_lime_800">#9E9D24</color>
<color name="material_lime_900">#827717</color>
<color name="material_lime_A100">#F4FF81</color>
<color name="material_lime_A200">#EEFF41</color>
<color name="material_lime_A400">#C6FF00</color>
<color name="material_lime_A700">#AEEA00</color>
<!--Yellow-->
<color name="material_yellow_50">#FFFDE7</color>
<color name="material_yellow_100">#FFF9C4</color>
<color name="material_yellow_200">#FFF59D</color>
<color name="material_yellow_300">#FFF176</color>
<color name="material_yellow_400">#FFEE58</color>
<color name="material_yellow_500">#FFEB3B</color>
<color name="material_yellow_600">#FDD835</color>
<color name="material_yellow_700">#FBC02D</color>
<color name="material_yellow_800">#F9A825</color>
<color name="material_yellow_900">#F57F17</color>
<color name="material_yellow_A100">#FFFF8D</color>
<color name="material_yellow_A200">#FFFF00</color>
<color name="material_yellow_A400">#FFEA00</color>
<color name="material_yellow_A700">#FFD600</color>
<!--Amber-->
<color name="material_amber_50">#FFF8E1</color>
<color name="material_amber_100">#FFECB3</color>
<color name="material_amber_200">#FFE082</color>
<color name="material_amber_300">#FFD54F</color>
<color name="material_amber_400">#FFCA28</color>
<color name="material_amber_500">#FFC107</color>
<color name="material_amber_600">#FFB300</color>
<color name="material_amber_700">#FFA000</color>
<color name="material_amber_800">#FF8F00</color>
<color name="material_amber_900">#FF6F00</color>
<color name="material_amber_A100">#FFE57F</color>
<color name="material_amber_A200">#FFD740</color>
<color name="material_amber_A400">#FFC400</color>
<color name="material_amber_A700">#FFAB00</color>
<!--Orange-->
<color name="material_orange_50">#FFF3E0</color>
<color name="material_orange_100">#FFE0B2</color>
<color name="material_orange_200">#FFCC80</color>
<color name="material_orange_300">#FFB74D</color>
<color name="material_orange_400">#FFA726</color>
<color name="material_orange_500">#FF9800</color>
<color name="material_orange_600">#FB8C00</color>
<color name="material_orange_700">#F57C00</color>
<color name="material_orange_800">#EF6C00</color>
<color name="material_orange_900">#E65100</color>
<color name="material_orange_A100">#FFD180</color>
<color name="material_orange_A200">#FFAB40</color>
<color name="material_orange_A400">#FF9100</color>
<color name="material_orange_A700">#FF6D00</color>
<!--Deep Orange-->
<color name="material_deep_orange_50">#FBE9E7</color>
<color name="material_deep_orange_100">#FFCCBC</color>
<color name="material_deep_orange_200">#FFAB91</color>
<color name="material_deep_orange_300">#FF8A65</color>
<color name="material_deep_orange_400">#FF7043</color>
<color name="material_deep_orange_500">#FF5722</color>
<color name="material_deep_orange_600">#F4511E</color>
<color name="material_deep_orange_700">#E64A19</color>
<color name="material_deep_orange_800">#D84315</color>
<color name="material_deep_orange_900">#BF360C</color>
<color name="material_deep_orange_A100">#FF9E80</color>
<color name="material_deep_orange_A200">#FF6E40</color>
<color name="material_deep_orange_A400">#FF3D00</color>
<color name="material_deep_orange_A700">#DD2C00</color>
<!--Brown-->
<color name="material_brown_50">#EFEBE9</color>
<color name="material_brown_100">#D7CCC8</color>
<color name="material_brown_200">#BCAAA4</color>
<color name="material_brown_300">#A1887F</color>
<color name="material_brown_400">#8D6E63</color>
<color name="material_brown_500">#795548</color>
<color name="material_brown_600">#6D4C41</color>
<color name="material_brown_700">#5D4037</color>
<color name="material_brown_800">#4E342E</color>
<color name="material_brown_900">#3E2723</color>
<!--Grey-->
<color name="material_grey_50">#FAFAFA</color>
<color name="material_grey_100">#F5F5F5</color>
<color name="material_grey_200">#EEEEEE</color>
<color name="material_grey_300">#E0E0E0</color>
<color name="material_grey_400">#BDBDBD</color>
<color name="material_grey_500">#9E9E9E</color>
<color name="material_grey_600">#757575</color>
<color name="material_grey_700">#616161</color>
<color name="material_grey_800">#424242</color>
<color name="material_grey_900">#212121</color>
<!--Blue Grey-->
<color name="material_blue_grey_50">#ECEFF1</color>
<color name="material_blue_grey_100">#CFD8DC</color>
<color name="material_blue_grey_200">#B0BEC5</color>
<color name="material_blue_grey_300">#90A4AE</color>
<color name="material_blue_grey_400">#78909C</color>
<color name="material_blue_grey_500">#607D8B</color>
<color name="material_blue_grey_600">#546E7A</color>
<color name="material_blue_grey_700">#455A64</color>
<color name="material_blue_grey_800">#37474F</color>
<color name="material_blue_grey_900">#263238</color>
</resources>
I have recently had to have a random non repeating numbers. So I used these 2 methods to first generate the set and then shuffle it.
The example will generate numbers 1..99 in a random order.
function generateNumArr(limit) {
ret = [];
for (var i = 1; i < limit; i++) {
ret.push(i);
}
return ret;
}
function shuffle(array) {
var i = array.length,
j = 0,
temp;
while (i--) {
j = Math.floor(Math.random() * (i+1));
// swap randomly chosen element with current element
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}
var ranNums = shuffle(generateNumArr(100));
Please let me know in the comments what you think about this method.
I have recently found myself writing this code and I wondered, should I be writing such code at all? Is it too obscure?
return (tokens!= null && tokens.length >=1 && tokens[0].compareToIgnoreCase("NIL") != 0) ? tokens[0] : null;
It is pretty straightforward but it will require some mental power to process this code.
It is a often advocated that the code should be self documenting and I think it indeed should. Some thinkg only hacks and edge cases have to be documented but I still think placing notes in the strategic places in the code saying in a few words (few here means literally 3 to 5 words) what this piece of code does/is supposed to do.
Developers often take pride in complex and obscure code. This is, I guess some sort of narcissism in a shape of saying “I am so smart” instead of “I am so pretty”. Let’s call this the “Narcissistic code complexity syndrome”
Many times I do prefer writing such code however because I like the conciseness of it. Maybe I am deluding myself and I actually am a victim of narcissistic code complexity syndrom?
Let me know in the comments.
Here’s the recipe to remove the lib folder. You can change the file/path matching and also limit the command for range of commits because what it actually does is basically overwriting the history and removing the unwanted files.
git filter-branch --index-filter 'git rm --cached --ignore-unmatch lib/*' --tag-name-filter cat -- --all
git push --force
This will clean the unwanted lib folder from the repository completely
It will not rewrite the log commits though and the commit messages will still be there.
[This is an update to post on how to remove Pods folder from iOS project]
TL;DR
add the css into your ~/.atom/style.less which you can open from Atom -> Open Your Stylesheet.
Yesterday following the fix of many major issues I had with Atom where one of the major ones being the save state issue which I missed so much from Sublime and this was a deal breaker for me. Up until tomorrow when I realized it has been finally implemented in Atom.
I completely switched to Atom now. So long sublime… Or so I hope :)
I have realized that the search highlighting in the dark themes (I use Dark Monokay pretty much everywhere) and I used a custom Monokai theme in Atom that I changed a little to match better the Sublime Text Monokai theme I have been using for a while.
Anyhow. I realized that there is no search highlighting for me going on. Ok, so I thought maybe it’s me and tried some other dark themes. Nada yada…
Fortunately it’s a pretty easy fix via the custom styles that will apply to any theme you load:
atom-text-editor::shadow .highlight.find-result .region {
background: red;
}
atom-text-editor::shadow .highlight.current-result .region,
atom-text-editor::shadow .highlight.current-result ~ .highlight.selection .region {
background: red; // the active search highlight - to distinguish from the other results
border-color: yellow;
}
After playing a little with various options I decided to settle on these. You can of course change the background and the border to your liking.
The red used here is the default one and is rgb(255, 0, 0).
UPD (2015-11-01) As of October 2015, the colors are broken with the updated Atom. I still did not have the chance to fix it.
UPD (2015-12-10) I got some time to have a quick fix for the search highlight issue