Skip to content

Instantly share code, notes, and snippets.

View hiulit's full-sized avatar
💻
Working

hiulit

💻
Working
View GitHub Profile
@hiulit
hiulit / m-keep-ratio.styl
Last active June 13, 2016 09:48
Stylus mixin to easily keep the aspect ratio.
/*
The HTML structure should be something like this:
<div class="box">
<div class="box__content">
// Images or whatever inside
</div>
</div>
@hiulit
hiulit / ajax-loop.js
Created December 19, 2016 15:57
Automatically try AJAX request again on fail
var attempts;
function doAjaxRequest() {
attempts = 0;
doAjaxRequestLoop();
}
function doAjaxRequestLoop() {
attempts += 1;
if (attempts > 10) {
alert('too many attempts.');
@hiulit
hiulit / WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED.txt
Last active March 24, 2017 23:59
WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED
ssh-keygen -R "you server hostname or ip"
@hiulit
hiulit / flexbox-issues-ie.md
Last active May 18, 2017 09:26
Flexbox issues with IE

Flexbox issues with IE

Inline elements inside flex container don't wrap

display: block;
width: 100%;

Children of flex-column don't adjust height properly

@hiulit
hiulit / remove-ds_store-files-mac-osx.txt
Created May 29, 2017 08:41
How to Recursively Remove .DS_Store Files on Mac OS X
// Credits https://medium.com/@danilosapad/how-to-recursively-remove-ds-store-files-on-mac-os-x-6c8570c68ad0
* Open Terminal.
* Go to desired folder.
* Type `find . -name *.DS_Store -type f -delete`.
@hiulit
hiulit / convert_unhyphenated_datetime.sh
Created February 28, 2018 11:53
Convert unhyphenated datetime (20180228T125033) into 2018-02-28T12:50:33
date="$(echo "20180228T125033" | cut --output-delimiter=$'-' -c1-4,5-6,7-8)"
time="$(echo "20180228T125033" | cut --output-delimiter=$'-' -c10-11,12-13,14-15)"
date --utc --date "$date $time" +%s
@hiulit
hiulit / xmlstarlet_delete_tag_value.sh
Created February 28, 2018 11:55
xmlstarlet delete tag containing certain value
xmlstarlet ed -L -d "/path/to/tag[contains(text(),'some text')]" "path/to/file"
@hiulit
hiulit / show_git_branch_macos_terminal.md
Last active March 12, 2018 15:32
Show git branch on macOS Terminal
  • Open the Terminal and enter open ~/.bash_profile
  • At the end of the file, paste the code below:
# Git branch in prompt.
parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ "
@hiulit
hiulit / stylus-variables-usage-with-string-interpolation.styl
Last active April 20, 2018 09:23
Stylus variables usage with string interpolation (e.g. when using the calc() function)
$some-variable = 10px
body
width: "calc(100% - %s)" % $some-variable
// To use multiple variables wrap the values into round brackets.
$some-variable = 10px
$another-variable = 5px
@hiulit
hiulit / sort-array-object.js
Created April 27, 2018 11:29
Simple function to sort an array of objects
function sortByKey(array, key) {
return array.sort(function(a, b) {
var x = a[key];
var y = b[key];
if (typeof x == "string") {
x = (""+x).toLowerCase();
}
if (typeof y == "string") {
y = (""+y).toLowerCase();
}