Skip to content

Instantly share code, notes, and snippets.

View siliconprime-chinh's full-sized avatar

Chinh Bui siliconprime-chinh

View GitHub Profile
// note that we restricted age to accept numbers only
function addOne(age: number): number {
return age + 1;
}
console.log(addOne(32));
//console.log(addOne("thirty two"));
@siliconprime-chinh
siliconprime-chinh / ScreenshotViewController.swift
Created March 6, 2018 10:18 — forked from kiichi/ScreenshotViewController.swift
Example to capture the NSView screenshot in Mac App
import Cocoa
class ScreenshotViewController: NSViewController {
override func prepareForSegue(segue: NSStoryboardSegue, sender: AnyObject?) {
if let viewController = segue.destinationController as? PreviewViewController{
viewController.image = getScreenshot()
}
}
func getScreenshot() -> NSImage {
@siliconprime-chinh
siliconprime-chinh / 1.swift
Last active March 1, 2018 06:19
How to capture UIView to UIImage without loss of quality on retina display
func imageWithView(inView: UIView) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(inView.bounds.size, inView.isOpaque, 0.0)
defer { UIGraphicsEndImageContext() }
if let context = UIGraphicsGetCurrentContext() {
inView.layer.render(in: context)
let image = UIGraphicsGetImageFromCurrentImageContext()
return image
}
return nil
}
<?
$entities = array('image', 'photo', 'text', 'source', 'site', 'traffic', 'money', 'book', 'e-book', 'file', 'smartphone', 'camera', 'notebook', 'cities', 'distances', 'cars', 'mobile', 'book', 'sex', 'love', 'classifieds', 'ads', 'alcohol', 'travel');
$verbs = array('sell', 'buy', 'rent', 'exchange', 'free', 'give', 'book', 'clean', 'find', 'classify', 'compare');
echo '<table style="width: 100%">';
foreach ($entities as $entity)
{
echo '<tr>';
foreach ($verbs as $verb)
echo "<td style='font-size: 14px; padding: 5px; text-align: center'>$verb $entity</td>";
echo '</tr>';
Response: <NSHTTPURLResponse: 0x600000228a00> { URL: http://directapi.codehub.io/products/58d0a7c6826d4f21b890882a } { status code: 200, headers {
"Access-Control-Allow-Headers" = "Origin, X-Requested-With, Content-Type, Accept, Authorization, ApiKey, AppVersion";
"Access-Control-Allow-Methods" = "GET,PUT,POST,DELETE,PATCH,OPTIONS";
"Access-Control-Allow-Origin" = "*";
Connection = "keep-alive";
"Content-Length" = 3714;
"Content-Type" = "application/json; charset=utf-8";
Date = "Tue, 21 Mar 2017 08:21:10 GMT";
Etag = "W/\"e82-IGkUHdRs0eFHVrwELjz6VahSzG8\"";
Server = "nginx/1.4.6 (Ubuntu)";
@siliconprime-chinh
siliconprime-chinh / uninstall_homebrew.sh
Created December 18, 2015 06:32 — forked from mxcl/uninstall_homebrew.sh
Uninstall Homebrew
#!/bin/sh
# Just copy and paste the lines below (all at once, it won't work line by line!)
# MAKE SURE YOU ARE HAPPY WITH WHAT IT DOES FIRST! THERE IS NO WARRANTY!
function abort {
echo "$1"
exit 1
}
set -e