Skip to content

Instantly share code, notes, and snippets.

Charles Ying charlietuna

Block or report user

Report or block charlietuna

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
charlietuna / rc4.swift
Last active Jul 29, 2016
RC4 in Swift
View rc4.swift
func RC4(🔏:[UInt8], 🔑:[Int]) -> [UInt8]
var i = 0, j = 0, S = Array(0...255)
for i in 0...255 {
j = (j + S[i] + 🔑[i % 🔑.count]) % 256
(S[j], S[i]) = (S[i], S[j])
i = 0; j = 0
return 🔏.map {
i = (i + 1) % 256; j = (j + S[i]) % 256
charlietuna /
Last active Mar 17, 2016
RSA in 4 lines of Python.
#!/usr/bin/python # Usage: exponent modulus < plaintext > ciphertext
from sys import*;from string import*;a=argv;[s,p,q]=filter(lambda x:x[:1]!=
'-',a);d='-d'in a;e,n=atol(p,16),atol(q,16);l=(len(q)+1)/2;o,inb=l-d,l-1+d
while;s and map(stdout.write,map(lambda i,b=pow(reduce(
lambda x,y:(x<<8L)+y,map(ord,s)),e,n):chr(b>>8*i&255),range(o-1,-1,-1)))
View google.logo
#!/usr/bin/env python
# -*- coding: utf-8 -*-
pip install networkx distance pattern
In Flipboard's article[1], they kindly divulge their interpretation
of the summarization technique called LexRank[2].
charlietuna / homestyle-edits.css
Created May 13, 2014
Refactor of The Incomparable HTML and CSS
View homestyle-edits.css
font-family: HelveticaNeue-Medium, "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: large;
background-color: #252b6f;
color: white;
text-align: center;
a, a:visited, a:hover { color: white; }
charlietuna / inv_sqrt_rrrlog.c
Created Apr 9, 2014
Improved (over John Carmack's) inverse square root hack from Řrřola -
View inv_sqrt_rrrlog.c
float inv_sqrt(float x)
union { float f; uint32 u; } y = {x};
y.u = 0x5F1FFFF9ul - (y.u >> 1);
return 0.703952253f * y.f * (2.38924456f - x * y.f * y.f);
charlietuna / gist:6336352
Created Aug 25, 2013
For people who are interested in learning about compiler optimizations
View gist:6336352
Expression related optimizations: Constant Folding, Constant Propagation, Global Propagation, Strength Reduction, Common Subexpression Elimination, Partial Redundancy Elimination, Induction Variable Elimination, Reassociation
Loop related optimizations: Loop Invariant Code Motion, Loop Peeling, Loop Unrolling, Loop Distribution, Loop Autoparallelization, Loop Fusion, Loop Fission, Loop Interchange, Loop Tiling/Stripmining, Vectorization, Scalarization
Memory/cache related optimizations: Cache blocking, False Sharing Elimination, Structure Peeling, Structure Splitting, Array Contraction, Multi-dimensional Array Dimension Reordering
Control flow related optimizations: Code block re-ordering (by frequency), Branch prediction (by static analysis/feedback guided), Code hoisting/sinking (to optimize CPU pipeline), Automatic Inlining, Tail Call Optimization
Code generation related optimizations: Register allocation (np complete), Peephole optimization, Superoptimization (no one really does this yet, but cool nonethe
charlietuna / permute_list
Created Apr 23, 2013
Takes a list and returns an array of permutations of that list.
View permute_list
permute_list = (list) ->
if list.length <= 1
return [ list ]
permutations = []
for first, i in list
restOfList = list.slice()
restOfList.splice(i, 1)
for subperm in permute_list(restOfList)
permutations.push([ first ].concat(subperm))
return permutations
charlietuna / lldb-pwin.txt
Created Dec 11, 2012
LLDB .lldbinit tip for making a command alias for showing iOS UIKit's current view hierarchy.
View lldb-pwin.txt
command alias pwin expression -o -- (NSString *)[[UIWindow keyWindow] recursiveDescription]
You can’t perform that action at this time.