Skip to content

Instantly share code, notes, and snippets.

View ivanfoong's full-sized avatar

ivanfoong ivanfoong

View GitHub Profile
@ivanfoong
ivanfoong / swift_libraries_export.sh
Last active December 7, 2015 07:03
Dynamic libraries needed in Ubuntu 14.04 for running swift binary
#/usr/local/swift/lib/swift/linux/libswiftCore.so
#/usr/lib/x86_64-linux-gnu/libicuuc.so.52
#/usr/lib/x86_64-linux-gnu/libicui18n.so.52
#/usr/lib/x86_64-linux-gnu/libicudata.so.52
curl --upload-file /usr/local/swift/lib/swift/linux/libswiftCore.so https://transfer.sh/libswiftCore.so
curl --upload-file /usr/lib/x86_64-linux-gnu/libicuuc.so.52 https://transfer.sh/libicuuc.so.52
curl --upload-file /usr/lib/x86_64-linux-gnu/libicui18n.so.52 https://transfer.sh/libicui18n.so.52
curl --upload-file /usr/lib/x86_64-linux-gnu/libicudata.so.52 https://transfer.sh/libicudata.so.52
@ivanfoong
ivanfoong / web-servers.md
Created November 13, 2015 14:17 — forked from willurd/web-servers.md
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
import os
import random
import platform
try:
from msvcrt import getch #For windows
except ImportError: #For linux and maybe mac...
def getch():
import sys, tty, termios
fd = sys.stdin.fileno()
@ivanfoong
ivanfoong / SettingUpReactNative.md
Created October 26, 2015 01:45
Setting Up React Native

Installing react native

install nvm

$ curl -o- https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash

install and setup node

@ivanfoong
ivanfoong / AutoResizingTextViewController.swift
Created October 21, 2015 03:43
Auto resizing UITextView with AutoLayout based on text content in textview
import UIKit
class AutoResizingTextViewController: UIViewController, UITextViewDelegate {
lazy var contentView = UIView(frame: CGRect.zero)
lazy var textViewContainer = UIView(frame: CGRect.zero)
lazy var textView = UITextView(frame: CGRect.zero)
override func loadView() {
super.loadView()
@ivanfoong
ivanfoong / crash.java
Created September 17, 2015 01:38
Forcing crash in android
throw new RuntimeException("This is a forced crash");
@ivanfoong
ivanfoong / install.sh
Last active August 29, 2015 14:27
Android Studio Code Style
#!/bin/bash
# Installs Android Studio configs into your user configs.
echo "Installing code style configs..."
for i in $HOME/Library/Preferences/AndroidStudio*
do
if [ -d $i ]; then
mkdir -p $i/codestyles
cp -frv ivanfoong.xml $i/codestyles
@ivanfoong
ivanfoong / delay.swift
Created April 9, 2015 07:22
Swift method to delay execution of code
func delay(delay:Double, closure:()->()) {
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
Int64(delay * Double(NSEC_PER_SEC))
),
dispatch_get_main_queue()
, closure
)
}
@ivanfoong
ivanfoong / HexToUIColor.m
Last active December 31, 2015 19:29
Hex to UIColor
//RGB color macro
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
//RGB color macro with alpha
#define UIColorFromRGBWithAlpha(rgbValue,a) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:a]
UIColor *color = UIColorFromRGB(0xCECECE);
UIColor *color2 = UIColorFromRGB(0xCECECE, 0.8);
@ivanfoong
ivanfoong / external_ip.rb
Created November 18, 2013 11:51
Check external IP address
require 'open-uri'
remote_ip = open('http://whatismyip.akamai.com').read
p remote_ip