Skip to content

Instantly share code, notes, and snippets.

View cybersamx's full-sized avatar

Samuel Chow cybersamx

  • Los Angeles, Ca
  • 05:23 (UTC -08:00)
View GitHub Profile
@cybersamx
cybersamx / flyte-consume-api-eager.py
Last active October 15, 2024 17:40
Execute Flyte Tasks Concurrently using map_task and eager
# This script performs the same thing as flyte-consume-api-maptask.py but it runs
# the "tasks" concurrently within a pod using the eager task.
from flytekit import task
from flytekit.experimental import eager
from dataclasses import dataclass
from dataclasses_json import dataclass_json
import requests
@cybersamx
cybersamx / ssh-key-generation.md
Last active June 15, 2024 08:26
Generate a new SSH key pair

Mac and Linux

  • Open Terminal

  • Check if you already have a SSH keypair generated. Do the following:

    $ ls -la ~/.ssh/id_rsa*
    

If the files exist, you already have SSH installed. IMPORTANT: But if you wish to regenerate the SSH key pair, at least back up your old SSH keys.

@cybersamx
cybersamx / sed_match_n_replace
Last active August 29, 2015 14:16
Ways for sed to match and replace lines
# Remove all occurences of string_to_match
sed -i '/string_to_match/d' file
# Match and add new string line
sed -i '/string_to_match/a new_string' file
# Match string and replace the entire line with string line
sed -i '/string_to_match/c\new_string' file
# Match the string and replace with sring
@cybersamx
cybersamx / curl_commands.sh
Last active August 29, 2015 14:05
Commonly used CURL commands for testing/debugging
# GET a JSON result.
curl -i -H "Accept: Application/json" -H "Content-Type: application/json" http://localhost/sessions.json
# POST a JSON result.
curl -X POST -H "Accept: Application/json" -H "Content-Type: application/json" -d '{"id":"IDVALUE","name":"Sam"}' http://localhost/sessions.json
# Use cookies (write/read).
curl -c cookies.txt -b cookies.txt http://localhost/users.json
# Follow redirection.
@cybersamx
cybersamx / NSDateFormatter_DateFormatSpecifiers.m
Last active August 29, 2015 14:04
NSDateFormatter date format specifiers
[dateFormatter setDateFormat:@"E, d M y"]; // Output: Sun, 1 5 2011
[dateFormatter setDateFormat:@"EE, dd MM yy"]; // Output: Sun, 01 05 11
[dateFormatter setDateFormat:@"EEE, ddd MMM yyy"]; // Output: Sun, 001 May 2011
[dateFormatter setDateFormat:@"EEEE, dddd MMMM yyyy"]; // Output: Sunday, 0001 May 2011
[dateFormatter setDateFormat:@"EEEEE, ddddd MMMMM yyyyy"]; // Output: S, 00001 M 2011
// Common date format specifiers
//
// y = year
// Q = quarter
@cybersamx
cybersamx / CoordinatesOfSubView.m
Created August 6, 2014 17:58
To find the coordinate of subview in the view controller view coordinate system.
// Create nested subviews. self.view > subview1 > subview2
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 20, 300, 300);
[self.view addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30, 200, 200);
[superview addSubview:subview2];
// To find the coordinate of subview in the view controller view coordinate system.
CGPoint point = [subview1 convertPoint:subview2.frame.origin toView:self.view];
@cybersamx
cybersamx / UIStretchedButton.m
Last active August 29, 2015 14:04
Create a custom UIButton with a custom background image and stretchable width.
// 1. Create a PNG background image.
// 2. Use UIEdgeInsets to stretch the image eg. 8.0f left and right of rect to remain unstretched
// 3. Make sure the UIButton height is the same as the image height
UIImage *image = [UIImage imageNamed:@"button_background_blue.png"];
UIEdgeInsets insets = UIEdgeInsetsMake(0.0f, 8.0f, 0.0f, 8.0f);
UIImage *stretchedImage = [image resizableImageWithCapInsets:insets];
[self.button setBackgroundImage:stretchedImage forState:UIControlStateNormal];
@cybersamx
cybersamx / UIViewSnapshot.m
Created August 6, 2014 17:39
Create a UIImageView representing a visual snapshot of another UIView object.
- (UIImageView *)createSnapshotFromView:(UIView *view) {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return [[UIImageView alloc] initWithImage:snapshotImage];
}