Skip to content

Instantly share code, notes, and snippets.

View ilovejs's full-sized avatar
🐡

Hao ilovejs

🐡
  • 19:50 (UTC +10:00)
View GitHub Profile
------------------------------
String:
$mystr = "Jello, world?";
$mystr{0} = "H";
$mystr{12} = "!";
print $mystr;
------------------------------
Octal:
@ilovejs
ilovejs / mvc4inAction
Created June 23, 2014 13:49
Notes for asp.net mvc 4 in action
//Server side
public ViewResult Show(int id)
{
var entry = _db.Entries.Find(id);
bool hasPermission = User.Identity.Name == entry.Name;
ViewData["hasPermission"] = hasPermission;
return View(entry);
}
//View
@ilovejs
ilovejs / scala.sc
Created July 26, 2014 13:42
worksheet of week1 for course <Functional Programming Principles in Scala>
import scala.annotation.tailrec
println("Welcome to the Scala worksheet") //> Welcome to the Scala worksheet
def loop: Boolean = loop
def abs(x: Double) = if (x < 0) -x else x
def and(x: Boolean, y:Boolean) = if (x) y else false
//> and: (x: Boolean, y: Boolean)Boolean
and(true, true) //> res0: Boolean = true
and(true, false) //> res1: Boolean = false
# Examples from http://andreypopp.com/posts/2012-10-30-callbacks-to-promises.html
# using IcedCoffeeScript http://maxtaco.github.com/coffee-script/ :
search = (engine, q, cb) ->
$.ajax(url: engine, success: cb)
await
search 'google', 'js', defer(googleSearched)
search 'bing', 'js', defer(bingSearched)
processResults(bingSearched, googleSearched)
await
@ilovejs
ilovejs / CMD_Create_link_for_folder.bat
Created August 5, 2014 02:48
CMD_Create_link_for_folder
@ilovejs
ilovejs / await_read_file.js
Created August 6, 2014 06:04
await_reading_file for tamejs
require('tamejs').register();
var fs = require('fs');
var filename = 'tjs/tokenFile.txt';
var token = '123456';
function readAccessCode(filename, cb){
var data;
await fs.readFile(filename, "utf-8", defer(err, data));
if(!err){
@ilovejs
ilovejs / HaskellBootstrap.hs
Created August 16, 2014 14:45
haskell bootstrap code
module Main where
myLast :: [a] -> a
myLast [x] = x
myLast (_:xs) = myLast xs
--myLast' = foldr1 (const id)
main = do
print (myLast [1,3,4])
@ilovejs
ilovejs / HaskellBootstrap2.hs
Created August 16, 2014 14:45
haskell bootstrap code 2
module Main where
--Find the last but one element of a list.
--Prelude> myButLast [1,2,3,4]
--3
myButLast :: [a] -> a
myButLast = take 2http://localhost:63342/react/examples/basic-commonjs/index.html
main = do
print (myButLast [1,3,4])
@ilovejs
ilovejs / goodSQL.sql
Created August 18, 2014 23:52
infoLead database script
select UserA.userID, UserA.userName--, tblLeads.ExhibitionID
from tblUsers as UserA
inner join
(
select count(userID) as noOfDuplicate, userName
from tblUsers
where username like('AGE14S%')
group by userName
having count(userID) > 1
) as DuplicateUser
#!/bin/bash
pretty print JSON from the command line
by RUSLAN SPIVAK on OCTOBER 12, 2010
Recently I’ve worked on a small project where I needed to pretty print JSON from the command line for quick verification.
For the task I created a pp alias in my .bashrc that worked perfectly (all the code is on the same line):
alias pp='python -c "import sys, json; print json.dumps(
json.load(sys.stdin), sort_keys=True, indent=4)"'
Just today I was re-reading the official Python documentation on a json package and came across a small gem – json.tool module that is used for validation and pretty-printing.