Skip to content

Instantly share code, notes, and snippets.

@xilin
xilin / repo-rinse.sh
Created September 21, 2020 11:07 — forked from nicktoumpelis/repo-rinse.sh
Cleans and resets a git repo and its submodules
git clean -xfd
git submodule foreach --recursive git clean -xfd
git reset --hard
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
@xilin
xilin / lc.js
Last active December 7, 2019 08:05
copy desc in leetcode for notion
var l = getEventListeners(document).copy[0];
document.removeEventListener('copy', l.listener, l.useCapture);
// change format so that codes inside `PRE` tag can show correctly in notion
for (let strong of [...document.getElementsByTagName('code')].filter(i => i.parentNode.tagName === 'PRE')) {
const textNode = document.createElement('span');
textNode.innerHTML = strong.innerHTML;
strong.parentNode.replaceChild(textNode, strong);
}
for (let strong of [...document.getElementsByTagName('strong')].filter(i => i.parentNode.tagName === 'PRE')) {
const textNode = document.createElement('span');
@xilin
xilin / wwdc.sh
Created November 4, 2019 07:51 — forked from idiomatic/wwdc.sh
Fetch WWDC videos, slides, and sample code.
#!/bin/bash
# usage: get [ RESOLUTION [ YEAR [ IDS... ] ] ]
resolution=${1:-SD}
year=${2:-2015}
shift
shift
ids=$*
RESOLUTION=$(echo $resolution | tr '[:lower:]' '[:upper:]')
@xilin
xilin / NSObject+Debounce.h
Created March 10, 2018 12:21 — forked from berzniz/NSObject+Debounce.h
Debounce method for Objective C
@interface NSObject (Debounce)
- (void)debounce:(SEL)action delay:(NSTimeInterval)delay;
@end
// A for nearly all cases reasonable good implementation was proposed in Josh Bloch's "Effective Java" in item 8. The best thing is to look it up there because the author explains there why the approach is good.
// A short version:
// 1) Create a int result and assign a non-zero value.
// 2) For every field tested in the equals-Method, calculate a hash code c by:
// If the field f is a boolean: calculate (f ? 0 : 1);
// If the field f is a byte, char, short or int: calculate (int)f;
@xilin
xilin / isBefore.js
Created December 20, 2013 07:37
Compare DOM tree order of elements
// http://stackoverflow.com/questions/3860351/relative-position-in-dom-of-elements-in-jquery
// What this does is .add() the additional element (or selector)
// (which jQuery keeps in document order) and then checks if it's the second of the two.
(function($) {
$.fn.isBefore = function(elem) {
if(typeof(elem) == "string") elem = $(elem);
return this.add(elem).index(elem) > 0;
}
})(jQuery)
@xilin
xilin / reload-table.m
Last active May 9, 2017 02:35
Reload table with a snapshot transition
// From https://github.com/facebookarchive/AsyncDisplayKit/issues/616#issuecomment-133422166
- (void)reloadData
{
UIView *snapshot = [_tableView snapshotViewAfterScreenUpdates:NO];
[self.view insertSubview:snapshot aboveSubview:_tableView];
[_tableView beginUpdates];
[_tableView reloadData];
[_tableView endUpdatesAnimated:NO completion:^(BOOL completed) {
@xilin
xilin / font-boosting.css
Created April 19, 2017 11:44 — forked from mojoaxel/font-boosting.css
Disable font boosting on mobile browsers
/* disable font boosting on mobile browsers */
body * {
max-height: 1000000em; /* Chrome for Android */
-moz-text-size-adjust: none; /* Firefox Mobile */
-webkit-text-size-adjust: 100%; /* Safari */
}
@xilin
xilin / gist:2c2040cfc8f306850222b73eb8218b3c
Created March 28, 2017 08:23 — forked from steipete/ios-xcode-device-support.sh
Using iOS 10.3 devices with Xcode 8.2.1
// The trick is to link the DeviceSupport folder from the beta to the stable version.
// Updated on Jan 24th, 2017 for Xcode 8.3b1
ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/10.3\ \(14E5230d\)/ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
// Then restart Xcode and reconnect your devices. You will need to do that for every beta of future iOS versions
// sudo needed if you run the Mac App Store version. Always download the dmg instead... you'll thank me later :)
@xilin
xilin / gist:8d3aed526fdbe6c5ecd34462e25fb0aa
Created December 21, 2016 05:09 — forked from karlcow/gist:2360574
curl empty user agent
→ curl -iI -v -A " " "http://www.la-grange.net/"
* About to connect() to www.la-grange.net port 80 (#0)
* Trying 128.30.54.58... connected
* Connected to www.la-grange.net (128.30.54.58) port 80 (#0)
> HEAD / HTTP/1.1
> User-Agent:
> Host: www.la-grange.net
> Accept: */*
>
< HTTP/1.1 200 OK