This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------------------------ | |
String: | |
$mystr = "Jello, world?"; | |
$mystr{0} = "H"; | |
$mystr{12} = "!"; | |
print $mystr; | |
------------------------------ | |
Octal: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mklink /D E:\lp2 %CD%\server | |
// /D is directory | |
%CD% holds current directory | |
It means: | |
Create E:\lp2 as a link map to server folder in current directory. | |
User should browse to a suitable foler forehand, then execute this command. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
myLast :: [a] -> a | |
myLast [x] = x | |
myLast (_:xs) = myLast xs | |
--myLast' = foldr1 (const id) | |
main = do | |
print (myLast [1,3,4]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. |