Skip to content

Instantly share code, notes, and snippets.

@jamesliu96
jamesliu96 / text2bf.c
Created March 6, 2014 12:33
A simple tool written in C, converting text into BrainFuck script.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
static unsigned sqr[]={0, 0, 0, 0, 0, 25, 36, 49, 64, 81, 100, 121, 144};
unsigned char oldch, ch, i;
unsigned TextLen;
FILE *in, *out;
if (argc != 3)
@jamesliu96
jamesliu96 / name.sh
Created March 10, 2014 06:31
A simple Shell script output my name by compiling the BrainFuck script as C source code
#!/bin/sh
echo '>++++++++[<+++++++++>-]<++.>++++[<++++++>-]<-.++++++++++++.--------.++++++++++++++.>+++++++++[<--------->-]<--.>++++++[<+++++++>-]<++.>+++++[<++++++>-]<-.++++++++++++.>++++++++++[<----------->-]<+++.' | sed '
s/\([-+]\)/\1\1*p;/g
s/</p--;/g
s/>/p++;/g
s/>/p++;/g
s/\./putchar(*p);/g
s/\[/while(*p){/g
s/\]/}/g
@jamesliu96
jamesliu96 / fuck.sh
Last active August 29, 2015 13:58
FUCK shell script
#!/bin/sh
printf "\033[5;31;40m";
echo " █████▒█ ██ ▄████▄ ██ ▄█▀";
echo "▓██ ▒ ██ ▓██▒▒██▀ ▀█ ██▄█▒ ";
echo "▒████ ░▓██ ▒██░▒▓█ ▄ ▓███▄░ ";
echo "░▓█▒ ░▓▓█ ░██░▒▓▓▄ ▄██▒▓██ █▄ ";
echo "░▒█░ ▒▒█████▓ ▒ ▓███▀ ░▒██▒ █▄";
echo " ▒ ░ ░▒▓▒ ▒ ▒ ░ ░▒ ▒ ░▒ ▒▒ ▓▒";
echo " ░ ░░▒░ ░ ░ ░ ▒ ░ ░▒ ▒░";
@jamesliu96
jamesliu96 / colors.sh
Last active August 29, 2015 13:58
Shell color test
#!/bin/sh
# use `printf "\033[{{STYLE}};{{FOREGROUND_COLOR}};{{BACKGROUND_COLOR}}m"` to set the color of all the output from the shell
# use `printf "\033[0m"` to reset
for attr in 0 1 4 5 7 ; do
echo "----------------------------------------------------------------"
printf "ESC[%s;Foreground;Background - \n" $attr
for fore in 30 31 32 33 34 35 36 37; do
for back in 40 41 42 43 44 45 46 47; do
@jamesliu96
jamesliu96 / extend.js
Created May 5, 2015 20:56
Prolong anything
/*! extend.js | Copyright (c) 2015 James Liu | Released under the MIT license */
var Extend=function(b,a){if("object"===typeof b&&"object"===typeof a)for(var c in a)b[c]=a[c]};
@jamesliu96
jamesliu96 / rails.sh
Created May 10, 2015 14:36
Install Ruby on Rails
#!/bin/sh
sudo apt-get update
sudo apt-get install gcc g++ make
sudo apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev
wget http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz
tar -xzf ruby-2.2.2.tar.gz
cd ruby-2.2.2/
./configure
make
@jamesliu96
jamesliu96 / explode.js
Created May 18, 2015 16:01
RangeError: Maximum call stack size exceeded
(function a() { a() })();
@jamesliu96
jamesliu96 / lzw.js
Created May 18, 2015 18:50
LZW implemented in JavaScript
/*!
* LZW.js
* Copyright (c) 2015 James Liu
* Released under the MIT license
*/
var LZW = {
compress: function(c) {
for (var b = 0, d = {}; 256 > b; b++) {
d[String.fromCharCode(b)] = b;
}
@jamesliu96
jamesliu96 / ub.js
Created May 19, 2015 08:05
U2B & B2U polyfill
/*!
* UB.js - U2B & B2U polyfill
* Copyright (c) 2015 James Liu
* Released under the MIT license
*/
;(function(c) {
c.utob = c.utob || function(c) {
return c.replace(/[\ud800-\udbff][\udc00-\udffff]|[^\x00-\x7f]/g, function(a) {
if (2 > a.length) {
var b = a.charCodeAt(0);
/*! UB.js | Copyright (c) 2015 James Liu | Released under the MIT license */
(function(c){c.utob=c.utob||function(c){return c.replace(/[\ud800-\udbff][\udc00-\udffff]|[^\x00-\x7f]/g,function(a){if(2>a.length){var b=a.charCodeAt(0);return 128>b?a:2048>b?String.fromCharCode(192|b>>>6)+String.fromCharCode(128|b&63):String.fromCharCode(224|b>>>12&15)+String.fromCharCode(128|b>>>6&63)+String.fromCharCode(128|b&63)}b=65536+1024*(a.charCodeAt(0)-55296)+(a.charCodeAt(1)-56320);return String.fromCharCode(240|b>>>18&7)+String.fromCharCode(128|b>>>12&63)+String.fromCharCode(128|b>>>
6&63)+String.fromCharCode(128|b&63)})};c.btou=c.btou||function(c){return c.replace(/[\u00c0-\u00df][\u0080-\u00bf]|[\u00e0-\u00ef][\u0080-\u00bf]{2}|[\u00f0-\u00f7][\u0080-\u00bf]{3}/g,function(a){switch(a.length){case 4:return a=((7&a.charCodeAt(0))<<18|(63&a.charCodeAt(1))<<12|(63&a.charCodeAt(2))<<6|63&a.charCodeAt(3))-65536,String.fromCharCode((a>>>10)+55296)+String.fromCharCode((a&1023)+56320);case 3:return String.fromCharCode((15&a.cha