Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Frank Li franklixuefei

🎯
Focusing
  • Microsoft
  • Seattle, Washington
View GitHub Profile
@jaskiratr
jaskiratr / chmod-400.cmd
Created Jun 29, 2018
Set permission of file equivalent to chmod 400 on Windows.
View chmod-400.cmd
# Source: https://stackoverflow.com/a/43317244
$path = ".\aws-ec2-key.pem"
# Reset to remove explict permissions
icacls.exe $path /reset
# Give current user explicit read-permission
icacls.exe $path /GRANT:R "$($env:USERNAME):(R)"
# Disable inheritance and remove inherited permissions
icacls.exe $path /inheritance:r
@hdodov
hdodov / iframechange.js
Last active Jul 20, 2021
HTML iframe URL change listener for tracking when a new iframe page starts to load
View iframechange.js
function iframeURLChange(iframe, callback) {
var lastDispatched = null;
var dispatchChange = function () {
var newHref = iframe.contentWindow.location.href;
if (newHref !== lastDispatched) {
callback(newHref);
lastDispatched = newHref;
}
@aspitz
aspitz / BidirectionalDictionary
Created Nov 2, 2014
Swift implementation of a bidirectional dictionary
View BidirectionalDictionary
struct BidirectionalDictionary<KeyType:Hashable, ValueType:Hashable>{
var keyToValue = [KeyType:ValueType]()
var valueToKey = [ValueType:KeyType]()
subscript(key:KeyType) -> ValueType? {
get {
return self.keyToValue[key]
}
set {
self.keyToValue[key] = newValue
@mluton
mluton / gist:3990658
Created Oct 31, 2012
Display UIActivityViewController in a Popover
View gist:3990658
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[@"something"] applicationActivities:nil];
self.popover = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
self.popover.delegate = self;
[self.popover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
@hsablonniere
hsablonniere / README.md
Created May 2, 2012
scrollIntoViewIfNeeded 4 everyone!!!
View README.md

scrollIntoViewIfNeeded 4 everyone!!!

This gist provides a simple JavaScript implementation of the non-standard WebKit method scrollIntoViewIfNeeded that can be called on DOM elements.

Usage

Just use the code in index.js in your app or website. You can see usage in the test page test.html.

The parent element will only scroll if the element being called is out of the view. The boolean can force the element to be centered in the scrolling area.

@shpakovski
shpakovski / Image.m
Created Feb 5, 2012
iOS: How to retrieve image dimensions without loading CGImage into memory
View Image.m
// This method requires ImageIO.framework
#import <ImageIO/ImageIO.h>
- (CGSize)sizeOfImageAtURL:(NSURL *)imageURL
{
// With CGImageSource we avoid loading the whole image into memory
CGSize imageSize = CGSizeZero;
CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)imageURL, NULL);
if (source) {
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:(NSString *)kCGImageSourceShouldCache];