Skip to content

Instantly share code, notes, and snippets.

View tocttou's full-sized avatar
🌴

Ashish Chaudhary tocttou

🌴
View GitHub Profile
[
{
"code": "EUR",
"symbol_native": "€",
"name": "Euro"
},
{
"code": "AED",
"symbol_native": "د.إ",
"name": "United Arab Emirates Dirham"
package main
import utils.oldFor
fun main(args: Array<String>) {
var n = 12
oldFor({ 0 }, { it < n }, { it + 1 }) {
println(it)
n /= 2
}
package utils
fun oldFor(
initialSetter: () -> Int,
limitingCondition: (Int) -> Boolean,
updater: (Int) -> Int,
codeBlock: (Int) -> Unit) {
var i = initialSetter()
while (limitingCondition(i)) {
codeBlock(i)
package
class FrequencyMap<K, Int>(
private val b: MutableMap<K, kotlin.Int>,
private val c: Map<K, kotlin.Int>)
: MutableMap<K, kotlin.Int> by b, Map<K, kotlin.Int> by c {
// Do something with b an c
}
package main
import utils.FrequencyMap
fun main(args: Array<String>) {
val mutableMapOne = mutableMapOf<Int, Int>()
val freqMapOne = FrequencyMap<Int, Int>(mutableMapOne)
freqMapOne.add(1, 3)
freqMapOne.add(1, 2)
freqMapOne.add(Pair(2, 2))
package utils
class FrequencyMap<K, Int>(private val b: MutableMap<K, kotlin.Int>)
: MutableMap<K, kotlin.Int> by b {
fun add(key: K, freq: kotlin.Int = 1) {
b.computeIfPresent(key) { _, b -> b + freq }
b.putIfAbsent(key, freq)
}
FROM php:7.0-apache
RUN apt update && \
apt install -y wget && \
cd /tmp && \
wget https://www.dotdeb.org/dotdeb.gpg && \
apt-key add dotdeb.gpg && \
rm dotdeb.gpg && \
echo "deb http://packages.dotdeb.org jessie all" >> /etc/apt/sources.list && \
apt update && \
apt install -y php7.0-mysql php7.0-xml && \
// no error handling
// code not checked to be working - just to illustrate how to do it
const crypto = require("crypto");
const mkdirp = require("mkdirp-promise");
const io = require("socket.io")();
const fs = require("fs");
const Docker = require("dockerode");
const byline = require("byline");
const StringDecoder = require("string_decoder").StringDecoder;
import React, { PureComponent } from 'react';
export default class SecondChild extends PureComponent {
render() {
console.log("Rendering!");
return (
<div>
{this.props.text}
</div>
);
import React, { Component } from 'react';
import FirstChild from './FirstChild';
import SecondChild from './SecondChild';
export default class Parent extends Component {
constructor(props, context) {
super(props, context);
this.state = {
text: Math.random()
};