Skip to content

Instantly share code, notes, and snippets.

View lzl124631x's full-sized avatar
💻
Learning

Richard Liu lzl124631x

💻
Learning
View GitHub Profile
@lzl124631x
lzl124631x / rename-folder.sh
Created December 5, 2022 06:41
Sony Rename Folder
# For Sony cameras, the date format for the folders is defined in https://helpguide.sony.net/ilc/1710/v1/en/contents/TP0001629784.html
# Here I convert it to yyyy-mm-dd
for dir in */; do
mv $dir "202${dir:3:1}-${dir:4:2}-${dir:6:2}"
done
@lzl124631x
lzl124631x / chase-credit-card-offers.js
Last active November 30, 2022 23:15
Extract Chase Credit Card Offers
var $ = (selector, startNode) => (startNode || document).querySelector(selector);
var $$ = (selector, startNode) => Array.from((startNode || document).querySelectorAll(selector));
var all = $$('.sixersoffers__container').map(x => {
return { name: $('img', x).attributes['alt'].value, offer: $('.sixerscontent-one', x).textContent, daysLeft: $('.sixerscontent-two', x).textContent, elem: x }
})
var interested = ['Best Buy', 'Starbucks', 'CVS', "McDonald's", "DoorDash", "Holiday Inn", "Under Armour", "Rite Aid", "Hyatt", "Tommy Hilfiger", "Office Depot", "Sam's Club", "Kohl"]
var format = (x) => x.map(x => `${x.name}\t${x.offer}\t${x.daysLeft}`).join('\n')
var filtered = all.filter(x => interested.some(i => x.name.toLowerCase().includes(i.toLowerCase())))
all.forEach(x => x.elem.style.border = '')
filtered.forEach(x => x.elem.style.border = 'solid 3px red')
@lzl124631x
lzl124631x / unique.js
Last active October 25, 2022 18:48
array unique (preserve order)
Array.prototype.getUnique = function() {
var o = {}, a = []
for (var i = 0; i < this.length; i++) {
if (o[this[i]]) continue;
o[this[i]] = 1;
a.push(this[i]);
}
return a
}
@lzl124631x
lzl124631x / copy.js
Created September 27, 2022 18:07
Copy String
function copy(str) {
// Chrome Console API is not available :( Have to use this way.
const el = document.createElement("textarea");
el.value = str;
el.setAttribute("readonly", "");
el.style.position = "absolute";
el.style.left = "-9999px";
document.body.appendChild(el);
el.select();
document.execCommand("copy");
@lzl124631x
lzl124631x / delete-branches.js
Last active November 29, 2018 07:12
Delete Useless Github Remote Branches
// 1. Go to Github Branches Page
// 2. Open Chrome Dev Tool Console (F12)
// 3. Paste this command into the console and run.
// 4. Paste your clipboard in bash command line and run.
copy('git push origin --delete ' + $$('a.branch-name').map(x => x.textContent).join(' '))
use admin
files = ls();
files.forEach((file) => {
regex=/\.\/(.*)\.md/g
parts=regex.exec(file)
if (parts == null) return
title=parts[1]
print(title)
content=cat(file)
print(content)
@lzl124631x
lzl124631x / droplet.css
Created August 14, 2016 02:38
CSS 3 Water Droplet
.droplet {
width: 1em;
height: 1em;
border-radius: 80% 0 55% 50% / 55% 0 80% 50%;
background-color: #07C;
transform: rotate(-45deg);
}
@lzl124631x
lzl124631x / js
Created August 14, 2016 01:43
get percentage css value from element
$.fn.pureCss = function (css) {
var $dummy = this.parent().clone().appendTo('body').hide();
var ret = $dummy.find(this.selector).css(css);
$dummy.remove();
return ret;
};
@lzl124631x
lzl124631x / js
Last active August 11, 2016 15:39
keep element's ratio
// http://codepen.io/lzl124631x/pen/xOmJGE
$.fn.keepRatio = function(ratio) {
var self = this,
$p = this.parent(),
keep = function() {
var w = $p.width(),
h = $p.height();
if (w / h > ratio) {
self.height(h);
self.width(h * ratio);
@lzl124631x
lzl124631x / html
Last active June 5, 2016 07:25
Html Meta: App Mode -- Not Scallable
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">