Skip to content

Instantly share code, notes, and snippets.

View vinceyang15's full-sized avatar

Yang Xi vinceyang15

  • Shanghai, China
View GitHub Profile
@vinceyang15
vinceyang15 / tokenizer.mll
Created June 30, 2016 15:50 — forked from lindig/tokenizer.mll
Some Scanning Recipes for OCamlLex
{
(* short names for important modules *)
module L = Lexing
module B = Buffer
type token =
| STR of string
| INT of int
| ID of string
| PLUSEQ
@vinceyang15
vinceyang15 / uniq.js
Last active August 29, 2015 14:21 — forked from stoimen/uniq.js
array.filter(function(elem, index, self) {
return self.indexOf(elem) === index;
});
@vinceyang15
vinceyang15 / apns_test.php
Created November 13, 2014 07:20
Test APNS script
<? php
$device = ''; // My iphone deviceToken
$payload['aps'] = array('alert' => 'This is the alert text', 'badge' => 1, 'sound' => 'default');
$payload['server'] = array('serverId' => 'localhost', 'name' => 'waach');
$output = json_encode($payload);
$apnsCert = 'apns-dev.pem';
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
@import url("/usr/share/gnome-shell/theme/gnome-shell.css");
/* customizing GNOME Shell for desktop interface
with fonts size 9pt (instead default 11pt size) */
/* Text Styles */
/* default text style */
stage {
font-size: 9pt; /* 11pt */
}
;;; minimial-cedet-config.el --- Working configuration for CEDET from bzr
;; Copyright (C) Alex Ott
;;
;; Author: Alex Ott <[email protected]>
;; Keywords: cedet, C++, Java
;; Requirements: CEDET from bzr (http://cedet.sourceforge.net/bzr-repo.shtml)
;; Do checkout of fresh CEDET, and use this config (don't forget to change path below)

Classes

  • class members (including data members) are public

  • all member functions are virtual

  • method function,

    • declared with an explicit first argument representing the object
    • the object is provided implicitly by the function call
  • classes are objects

  • Built-in types can be used as base classes

  • Operator overloading supported

Errors and Exceptions

1. Handle Exceptions

  • try ... except
while True:
	try:
		x = int(raw_input("Please enter a number: "))
		break

Input and Output

1. Output Formatting

  • str.format(): control formatting of output

  • str(): return representations of values, which are human-readable

  • repr(): genertate representations, readable by the interpreter

  • Many values have the same representation using either function. However, strings and float point numbers have distinct representations

     s = 'Hello, world.'

Module

  • Module: a file containing Python definitions and statements

  • File name is the module name, suffix .py

  • Module's name available as the global variable __name__

     # suppose we created a module called fib, which has two function fib and fib2
     # fib prints Fibonacci series up to n
     # fib2 returns Fibonacci series up to n
@vinceyang15
vinceyang15 / py_data_structure.md
Created February 24, 2014 15:30
Data Structure

Data Structures

1. Lists

  1. list.append(x), list[len(list):] = [x]
  2. list.extend(L), list[len(list):] = L
  3. list.insert(i, x)
  4. list.remove(x)
  5. list.pop(i), i is optional, if i is not specified, removes last one
  6. list.index(x)
  7. list.count(x)