This file contains hidden or 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
names.filter(name => name.indexOf('A') !== -1 ); |
This file contains hidden or 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
function filterNamesWithA(names) { // names is an array | |
return names.filter(function (name) { return name.indexOf('A') !== -1; }); | |
} |
This file contains hidden or 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
let panel = document.createElement('div'); | |
let button = document.createElement('button'); | |
button.addEventListener('click', function actionPerformed(e) { | |
// do stuff here | |
}); | |
panel.appendChild(button); |
This file contains hidden or 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
JPanel panel = new JPanel(); | |
panel.add(new JButton(new AbstractAction("name of button") { | |
public void actionPerformed(ActionEvent e) { | |
//do stuff here | |
} | |
})); |
This file contains hidden or 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
vector<pair<const char *,const char *>> tokenize_string2(const string &text); | |
auto v = tokenize_string2(get_input_string()); // Disaster strikes! | |
munge(v); |
This file contains hidden or 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
// borrowed from docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html | |
static String readFirstLineFromFileWithFinallyBlock(String path) throws IOException { | |
BufferedReader br = new BufferedReader(new FileReader(path)); | |
try { | |
return br.readLine(); | |
} finally { | |
if (br != null) br.close(); | |
} | |
} |
This file contains hidden or 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
// We need nested scopes here, because the intermediate results can keep | |
// large chunks of memory alive and we want to free them as soon as | |
// possible to keep the peak memory usage low | |
let (outputs, trans, sess) = { | |
let (outputs, expanded_crate, id) = { | |
let krate = phase_1_parse_input(&sess, cfg, input); | |
if stop_after_phase_1(&sess) { return; } | |
let outputs = build_output_filenames(input, | |
outdir, | |
output, |
This file contains hidden or 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
struct Point { | |
x: f64, | |
y: f64, | |
} | |
fn foo() { | |
{ | |
let p: Box<Point> = box Point { x: 1.0, y: 2.0 }; | |
} // p's heap memory is released! | |
} |
This file contains hidden or 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
class Foo : IDisposable { | |
// blah | |
} | |
// a couple thousand lines later... | |
using(Foo f = new Foo()) { | |
// blah | |
} |
This file contains hidden or 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
fn foo(x: Option<int>) { | |
match x { | |
Some(val) -> println!("{}", val), | |
None -> println!("Sad") | |
} | |
} |