Skip to content

Instantly share code, notes, and snippets.

View leewc's full-sized avatar

Wen Chuan Lee leewc

View GitHub Profile
@sj-dan
sj-dan / crosflex_downloader.sh
Last active December 10, 2023 12:22
Script to fetch and download the latest version of the Chrome OS Flex image
#!/bin/bash
URLs=$(curl "https://dl.google.com/dl/edgedl/chromeos/recovery/cloudready_recovery2.json" \
-s --output - | \
grep "^.*\"url\".*$" | \
sed "s/.*\"url\": \"\(.*\)\".*$/\1/g")
printf "\nPick which channel to download your image from. Channel name is near the end of the URL.\n\n"
select URL in $URLs;

10 Scala One Liners to Impress Your Friends

Here are 10 one-liners which show the power of scala programming, impress your friends and woo women; ok, maybe not. However, these one liners are a good set of examples using functional programming and scala syntax you may not be familiar with. I feel there is no better way to learn than to see real examples.

Updated: June 17, 2011 - I'm amazed at the popularity of this post, glad everyone enjoyed it and to see it duplicated across so many languages. I've included some of the suggestions to shorten up some of my scala examples. Some I intentionally left longer as a way for explaining / understanding what the functions were doing, not necessarily to produce the shortest possible code; so I'll include both.

1. Multiple Each Item in a List by 2

The map function takes each element in the list and applies it to the corresponding function. In this example, we take each element and multiply it by 2. This will return a list of equivalent size, compare to o

@jecxjo
jecxjo / passwd.sh
Last active September 23, 2015 02:33
BASH CGI Script for managing Unix Passwords
#!/bin/bash -
#===============================================================================
# Copyright (c) 2015 Jeff Parent
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
@lukehorvat
lukehorvat / es6-map-to-object-literal.js
Last active January 8, 2024 10:32
Convert ES6 Map to Object Literal
let map = new Map();
map.set("a", 1);
map.set("b", 2);
map.set("c", 3);
let obj = Array.from(map).reduce((obj, [key, value]) => (
Object.assign(obj, { [key]: value }) // Be careful! Maps can have non-String keys; object literals can't.
), {});
console.log(obj); // => { a: 1, b: 2, c: 3 }