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
| const insertAt = (str, sub, pos) => { | |
| return str.substring(0, pos) + sub + str.substring(pos); | |
| } | |
| console.log(insertAt("I want apple", " an", 6)); |
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
| int spi_write_then_write(struct spi_device *spi, | |
| const void *tx_buf_0, unsigned tx_len_0, | |
| const void *tx_buf_1, unsigned tx_len_1) | |
| { | |
| struct spi_message message; | |
| struct spi_transfer x[2]; | |
| spi_message_init(&message); | |
| memset(x, 0, sizeof(x)); | |
| if (tx_len_0) { |
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
| import scala.util.Random.nextInt | |
| def choosePivot(xs: List[Int]): Int = { | |
| if (xs.isEmpty) 0 | |
| else xs(nextInt(xs.length)) | |
| } | |
| def quicksort(xs: List[Int], p: Int): List[Int] = { | |
| if (xs.isEmpty) List() | |
| else if (xs.length == 1) xs |
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
| var str = 'allleee #psG !! tudu'; | |
| var regex = /#(\w+)/; | |
| str = str.replace(regex, "<b>#$1</b>"); |
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 Content | |
| def type | |
| self.class.name | |
| end | |
| end | |
| class TwitterContent | |
| def type | |
| "twitter" | |
| end |
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
| # app/assets/javascripts/welcome.js.coffee | |
| $ -> | |
| $(document).on 'change', '#countries_select', (evt) -> | |
| $.ajax 'update_cities', | |
| type: 'GET' | |
| dataType: 'script' | |
| data: { | |
| country_id: $("#countries_select option:selected").val() | |
| } |
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
| ## <...>: a mandatory parameter | |
| ## [...]: an optional parameter | |
| # Compare two versions of a file | |
| $ git diff HEAD^^ HEAD main.c | |
| $ git diff HEAD~2 HEAD main.c | |
| # Create a patch from a diff between two branches | |
| $ git format-patch -n <master>..<develop> |
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
| trait Generator[+T] { | |
| self => | |
| def generate: T | |
| def map[S](f: T => S): Generator[S] = new Generator[S] { | |
| def generate = f.apply(self.generate) | |
| } |
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
| def hexToInt(s: String): Int = { | |
| s.toList.map("0123456789abcdef".indexOf(_)).reduceLeft(_ * 16 + _) | |
| } | |
| def baseToInt(s: String, base: String): Int = { | |
| s.toList.map(base.indexOf(_)).reduceLeft(_ * base.length + _) | |
| } |
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
| def split[A](chars: List[A], n: Int): List[List[A]] = { | |
| if (chars.isEmpty) List() | |
| else chars.take(n) :: split[A](chars.drop(n), n) | |
| } | |
| def encrypt_rec(chars: List[List[Char]]): List[List[Char]] = { | |
| if (chars.isEmpty) Nil | |
| else { | |
| val cs = chars.filter(_.isEmpty == false) | |
| cs.map(_.head) :: encrypt_rec(cs.map(_.tail)) |
NewerOlder