Skip to content

Instantly share code, notes, and snippets.

@HungHuynh
HungHuynh / helloworld
Created August 29, 2011 04:05
Node.js : Hello World
var http = require('http')
http.createServer(function (req,res) {
res.writeHead(200, {'Content-Type':'text/plain'});
res.end('Hello World! \n');
}).listen(1337,"127.0.0.1");
console.log('Server running ar http://127.0.0.1:1337//');
@HungHuynh
HungHuynh / Blog post
Created August 29, 2011 12:43
Node.js : blog post
var http = require('http');
var url = require('url');
var fs = require('fs');
var newPostFormHTML = fs.readFileSync('views/post/new.html');
function renderNewPostForm(request, response) {
response.writeHead(200, {
'Content-type': 'text/html; charset=utf-8'
});
@HungHuynh
HungHuynh / getProcess
Created September 5, 2012 15:26
This is code sample about how get process runing background on iOS
#import <sys/sysctl.h>
- (NSArray *)runningProcesses {
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0};
size_t miblen = 4;
size_t size;
int st = sysctl(mib, miblen, NULL, &size, NULL, 0);
@HungHuynh
HungHuynh / sysctl API
Created September 5, 2012 15:30
This struct has information about running processes.You can run it in a loop until to get info about all processes. Here is a code snippet- extend it to get info of all processes
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_ALL;
mib[3] = 0;
ret = sysctl(mib, 4, NULL, &size, NULL, 0);
procs = malloc(size);
ret = sysctl(mib, 4, procs, &size, NULL, 0); /* procs is struct kinfo_proc.*/
@HungHuynh
HungHuynh / UIDevice-Process
Created September 5, 2012 15:53
UIDevice Category For Processes
@interface UIDevice (ProcessesAdditions)
- (NSArray *)runningProcesses;
@end
// .m
#import <sys/sysctl.h>
@implementation UIDevice (ProcessesAdditions)
- (NSArray *)runningProcesses {
@HungHuynh
HungHuynh / UIDevice-Platfform
Created September 6, 2012 03:48
This is function check type device
#include <sys/types.h>
#include <sys/sysctl.h>
@interface UIDevice(Hardware)
- (NSString *) platform;
- (BOOL)hasRetinaDisplay;
- (BOOL)hasMultitasking;
@HungHuynh
HungHuynh / checkDevice
Created September 15, 2012 20:27
Check device simulator or device real
//If it dont simulator :
#if !TARGET_IPHONE_SIMULATOR
#endif
#pragma mark - UIPickerViewDelegate methods
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
}
#pragma mark - UIPickerViewDataSource methods
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
}
@HungHuynh
HungHuynh / DetailViewController.h
Created September 30, 2012 08:27 — forked from anonymous/DetailViewController.h
Simple iOS YouTube App - Use this code to put a list of videos from a YouTube user in your app.
//
// DetailViewController.h
// youtubedemo
//
// Created by Your Name on 4/24/12.
// Copyright (c) 2012 Company Name. All rights reserved.
//
#import <UIKit/UIKit.h>
@HungHuynh
HungHuynh / ReasPKCS7
Created October 1, 2012 11:04
how to Read the certificates file from the PKCS7.p7b certificate file usind openssl
#include <stdio.h>
#include <openssl/pkcs7.h>
#include <openssl/x509.h>
#include <openssl/bio.h>
#include <openssl/pem.h>
int main(int argc, char **argv)
{
PKCS7 *p7 = NULL;
BIO *in = BIO_new(BIO_s_file());